PHP, MySQL, $_GET and If statement problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone,

I am having a issue that I have been working on for the last few days.
I am using PHP 5, MySQL 4.1 and PEAR.

The following code works by itself between <?php and ?> tags:

$isbn = $_GET['isbn'];
$sql = "DELETE FROM lounge WHERE isbn = $isbn";
print $sql;

Now, if I put it inside of an If statement, it does not work and I get
a "DB Error: syntax error":

if ($_POST['yes_no'] == 'yes') {
$isbn = $_GET['isbn'];
$sql = "DELETE FROM lounge WHERE isbn = $isbn";
print $sql;
} else {
print "Unable to delete record";

This isbn is stored as an INT in MySQL.  Does anyone have any ideas?  I
would really appreciate any feedback that anyone could give.  


Re: PHP, MySQL, $_GET and If statement problem wrote:
Quoted text here. Click to load it

Requests are generally made with either GET or POST, but not both.  So,
if $_POST['yes_no'] == 'yes' I wouldn't expect there to be any $_GET
variables.  Hence, your query, if you echo'ed it out would probably
look something like this:

DELETE FROM lounge WHERE isbn =  

which, of course, is not valid SQL.

Re: PHP, MySQL, $_GET and If statement problem

That was so easy.  It worked.  Thank you so much!  I inserted a hidden
field in my form and printed the $_GET value hidden fields value.  Then
I used $_POST to get the value of $isbn and ran that through the SQL
statement and it worked.  Thanks again!

Site Timeline