proper use of flush()
after reading up on flush at php.net, i'm still not quite sure how to use it where i want. i figured that i have two choices: play aaround and risk corrupting my db, or posting on this and getting advise from those with more experience, which, with any luck, will allow me to get it right the first time.
i'm trying to get the progress of the deletion to print to the screen as it occurs. here's the function that deletes a user (note, to even see this choice on the "admin page" you have to be a full administrator or the webmaster, and there's a double check in the function itself. all variables not taken from post or cookies or db retrievals, are set in the includes.)
(edited to prevent horizontal scrolling...)
<?php
function delu(){ # delete a user
include(\"/home/joshua/includes/fyd.altincs.php\"); # includes file
$un=$_COOKIE['un']; $pw=$_COOKIE['pw']; $deluser=$_POST['deluser'];
# check for access in the db
$db=mysql_connect($host, $login3, $pass3) or die(\"cannot access mysql\");
# connect to the db
$fyd=mysql_select_db('findyourdesire', $db) or die(\"cannot access db\");
# get the db
$accessfind=mysql_query(\"SELECT site_access FROM users WHERE username='$un'
AND password='$pw'\", $db);
$accessret=mysql_fetch_array($accessfind); $sa=$accessret['site_access'];
if(($sa!=$adm)&&($sa!=$wbm)){ error(); } # if not full admin or webmaster, error
else{ # we're authorized to delete
if(isset($_POST['action'])){ # we're gonna delete
$deluser=$_POST['deluser']; $gone=0; $errs='<p>';
$findinfo=mysql_query(\"SELECT uid,email FROM users WHERE username='$deluser'\",
$db);
if(mysql_num_rows($findinfo)){ // we found the user
$getinfo=mysql_fetch_array($findinfo); $email=$getinfo['email']; $todel=
$getinfo['uid']; $delerr=0;
if($_POST['reason']!=''){ # if there was a reason given for the deletion
$from='Administration_Of_FindYourDesire.com'; $reason=$_POST['reason'];
$message=\"Your account was terminated. If you join again and continue
this behaviour your ISP will be contacted.
Our reason for terminating your account:
$reason\";
mail($to, 'Deletion of your Account', $message, $from);
}
echo \" <p>Deleting $deluser...\n\"; $imgbase=$faup; $npib=$fuup;
foreach($images as $key=>$value){ # for each possible picture
echo \" <br />Checking for $value\n\"; $pica=$imgbase.$key.$deluser.
'.jpg';
$picb=$imgbase.'old.'.$key.$deluser.'.jpg'; $picc=$npib.$key.$deluser.
'.jpg';
/* delete the pics if they exist */
if(is_file($pica)){ unlink($pica); echo \" <br />Removing $pica\n\"; }
if(is_file($picb)){ unlink($picb); echo \" <br />Removing $picb\n\"; }
if(is_file($picc)){ unlink($picc); echo \" <br />Removing $picc\n\"; }
}
echo \" <br />Deleting of user $deluser from table BIO\";
$dfs=mysql_query(\"DELETE FROM bio WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){ // successful deletion
$gone++; echo \" <br />Removed $deluser (user # $todel) from table BIO\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
$errs.=\"<br />Bio:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table COMMENTS\";
$dfs=mysql_query(\"DELETE FROM comments WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table
COMMENTS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Comments:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table FRIENDS\";
$dfs=mysql_query(\"DELETE FROM friends WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table
FRIENDS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Friends:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table INTERESTS\";
$dfs=mysql_query(\"DELETE FROM interests WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table
INTERESTS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
$errs.=\"<br />Interests:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table MAIL\";
$dfs=mysql_query(\"DELETE FROM mail WHERE to_id='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table MAIL\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Mail:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table MSGS\";
$dfs=mysql_query(\"DELETE FROM msgs WHERE to_id='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table MSGS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Msgs:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table PESTS\";
$dfs=mysql_query(\"DELETE FROM pests WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table POSTS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Posts:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table POSTS\";
$dfs=mysql_query(\"DELETE FROM posts WHERE author='$deluser'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table POSTS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Posts:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table STATS\";
$dfs=mysql_query(\"DELETE FROM stats WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table STATS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
$errs.=\"<br />Stats:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table THREADS\";
$dfs=mysql_query(\"DELETE FROM threads WHERE thread_auth='$deluser'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel)
from table THREADS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Threads:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table TOPS\";
$dfs=mysql_query(\"DELETE FROM tops WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table TOPS\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Tops:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table VOTES\";
$dfs=mysql_query(\"DELETE FROM votes WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
$gone++; echo \" <br />Removed $deluser (user # $todel) from table VOTES\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db);
$errs.=\"<br />Votes:$errno: $error\";
}
$errs.='</p>';
if(!($delerr)){ # stats,bio,interests did not result in an error
(may be expanded to more)
echo \" <br />Deleting of user $deluser from table USERS\";
$dfs=mysql_query(\"DELETE FROM users WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){
echo \" <br />Deletion of user $deluser complete.</p>\n$errs\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
echo \"<br />Users:$errno: $error</p>\n$errs\";
}
}else{ // something is wrong
echo \" <br />Deletion of user $deluser encountered errors.
uid=$todel username=$deluser\";
echo \" </p>\n$errs\";
}
}else{ // we made a mistake
$errno=mysql_errno($db); $error=mysql_error($db); // what's wrong
$err=\"<p>query: SELECT uid,email FROM users WHERE username='$deluser'
<br />$errno:$error</p>\";
echo $err; // tell admin what went wrong
}
}
echo <<<END
<form action=\"$_SERVER[PHP_SELF]\" method=\"POST\" style=\"margin:0\">
<input type=\"hidden\" name=\"fn\" value=\"delu\">
<input type=\"hidden\" name=\"action\" value=\"delete\">
$tsnw
<tr><td><u>User Name</u></td><td><u>Reason</u></td><td>User Deletion
</td></tr>
<tr>
<td><input type=\"text\" name=\"deluser\" size=\"15\" maxlength=\"15\"></td>
<td><input type=\"text\" name=\"reason\" size=\"15\"></td>
<td><input type=\"submit\" value=\"Delete!\"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
END;
}
}
?>
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 17:05 — 15th September 2003.
He has: 4,048 posts
Joined: Aug 2000
flush() only sends whatever output is in the buffer to the client. There's no way it could corrupt your db, or otherwise alter the performance of your script.
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 18:31 — 15th September 2003.
They have: 461 posts
Joined: Jul 2003
ok. so that would mean i need to place it after each sql action? or at the end of all of them? (i want ti to update as it moves through them because it takes a little while since i'm on a p1 (pre-mmx)/166mhz processor)
ie:
<?php
echo \" <br />Deleting of user $deluser from table BIO\";
flush();
$dfs=mysql_query(\"DELETE FROM bio WHERE uid='$todel'\", $db);
if(mysql_affected_rows($db)==1){ // successful deletion
$gone++; echo \" <br />Removed $deluser (user # $todel) from table BIO\";
}else{ // error
$errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
$errs.=\"<br />Bio:$errno: $error\";
}
echo \" <br />Deleting of user $deluser from table COMMENTS\";
flush();
?>
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 00:54 — 18th September 2003.
He has: 4,048 posts
Joined: Aug 2000
That would work.
I usually put it at the bottom of the inside of large loops.
m3rajk posted this at 18:25 — 18th September 2003.
They have: 461 posts
Joined: Jul 2003
i did that so it would update as it moves from table to table. but it still didn't print out actively. went back and read it again. some browsers override flush. not sure if that's why it did that or not. i'm testing the site in mozilla 1.3.1 then making sure the display isn't too far off in ie.
i figure ie is going to be forgotten by the masses before M$ comes out with the new browser, so since i like mozilla that's what all the messages say to use if somethng's brokeni note it was tested in mozilla 1.3.1 and the person browseing should upgrade to the latest stable release of mozilla (i know it's at 1.4.1 but i'm going to upgrade after i complete the site simply so i'll know the site can be handled by 1.3.1 since alot of people i know only upgrade every 2 or 3 changes that aren't marked as security fixes)
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 18:49 — 22nd September 2003.
He has: 4,048 posts
Joined: Aug 2000
If the content your flushing is within certain HTML blocks (like tables), then the content wont be displayed untill the browser sees the end of the block.
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 18:30 — 23rd September 2003.
They have: 461 posts
Joined: Jul 2003
it's a set of lines with at the begining of each. i noticed in the write up it says that some browser override it (specifcally ie)
ROB posted this at 02:18 — 24th September 2003.
They have: 447 posts
Joined: Oct 1999
i think more specifically some servers override it, not browsers (while some browser may but i've never experienced it), in particular most or all Windows servers. They don't necessarily override it, they just provide their own buffering, so while the php app flushed it's still caught up in the webserver.
m3rajk posted this at 16:12 — 26th September 2003.
They have: 461 posts
Joined: Jul 2003
i'm using LAMP with mozilla and i didn't get ti sent actively. i got it all at once
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.