SQL not executing nor echoing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vfm
Forum Commoner
Posts: 32
Joined: Tue Mar 30, 2010 10:47 pm

SQL not executing nor echoing

Post by vfm »

Hi,

Can anyone see anything glaringly obvious with this PHP code? It's not even echoing my query to the browser!

Code: Select all

$email_address = $_POST['email_address'];

echo $email_address;

$que = mysql_query("DELETE FROM `member2` WHERE `email` = $email_address");

echo $que;
I can see the $email_address fine when it's being echoed but nothing below that seems to work.

Does anyone have any ideas?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: SQL not executing nor echoing

Post by mikosiko »

It's not even echoing my query to the browser!
this is your query:
[text]"DELETE FROM `member2` WHERE `email` = $email_address"[/text]

this is not
[text]$que[/text]

$que is a resultset
but nothing below that seems to work.
How do you know that nothing is working? (echo something incorrectly is not the way to test it)

you can do this:

Code: Select all

$que = mysql_query("DELETE FROM `member2` WHERE `email` = $email_address") or die("Query Error " . mysql_error());
to detect if something is wrong with your query

or test if your query was successful using in this case mysql_affected_rows() immediately after.. per example:

Code: Select all

if (mysql_affected_rows() > 0) {
   echo "Record(s) Deleted";
} else {
  echo "Delete Query didn't delete any record";
}
vfm
Forum Commoner
Posts: 32
Joined: Tue Mar 30, 2010 10:47 pm

Re: SQL not executing nor echoing

Post by vfm »

Great thanks for the tip! It told me what the problem was and I was able to fix it!
Post Reply