Jump to content

its not showing right if i do a query. no matter what it echos sucessful wtf?


emopoops

Recommended Posts

$flush55 = mysql_query("DELETE FROM dumps WHERE id='$flushing' AND time = '$wow'");
$flush2 = mysql_query("DELETE FROM tp WHERE dump = '$flushing'");
if($flush55){echo "SUCCESSFULLY FLUSHED THE DUMP HON!<br>";}

i dont understand because the variables arent the right ones (like i put in fake ones because they are coming from a $_GET POST.. to see if people could mass delete stuff and no matter what it says sucessful, and THERE IS NOTHING BEING DELETED halp!

it seems to me like the query is being successful. keep in mind that just because it is successful does not mean that it actually did anything. It could have went through the database and looked for values that matched your criteria but didnt find any so it did nothing. However, that would show as successful because it didnt get any errors along the way. But if there was an error in there then it would not show as successful. You should try passing values that you know meet your criteria and check the data then because hte query looks fine. you could always do an or die(mysql_error()) after your query to see if there was an error.

oh ok well i was just thinking if it was sucessful that meant it actually did something..

well how can i check if it did something? or better yet how can i check if it didnt do anything so i can hold off on putting out the "SUCCESS" echo

you could do something like this:

 

$flush55 = mysql_query("DELETE FROM dumps WHERE id='$flushing' AND time = '$wow'");
$flush2 = mysql_query("DELETE FROM tp WHERE dump = '$flushing'");

if($flush55 && mysql_affected_rows() > 0){
  echo "SUCCESSFULLY FLUSHED THE DUMP HON!<br>";
} else {
  echo "no rows affected";
}

 

The mysql_affected_rows is just a count of the number of rows that were changed. so all I did was add a check to see if the affect rows is greater than 0 (basically a row was changed).

THANK YOU that function is just what i will use. BUT do u or anyone know about the %d\n in the thing from the php manual for that function.

/* this should return the correct numbers of deleted records */
mysql_query('DELETE FROM mytable WHERE id < 10');
printf("Records deleted: %d\n", mysql_affected_rows());

i took it out and it didnt work

it is a placeholder for mysql_affected_rows(). the printf() function takes 2 or more arguments the first one is a string, the second is variables. anthing that is set with a % sign infront of it is a placeholder for a variable. the d after the % means that it is going to be an integer (see sprintf() for format http://www.php.net/manual/en/function.sprintf.php) heres a few examples:

 

$name = 'nick';
$age = 23;
printf('My name is %s and my age is %d.', $name, $age);

 

So this would show this on the screen:

My name is nick and my age is 23.

printf and sprintf are different functions like cags said but if you look at the print f page it links you to the sprintf page for the format, which is why i sent you a link to that page. it shows you how to use the %d and %s

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.