468,251 Members | 1,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,251 developers. It's quick & easy.

PHP, MySQL, $_GET and If statement problem

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";
$db->query($sql);
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";
$db->query($sql);
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.

Thanks!

Aug 14 '06 #1
2 6341

mp*****@gmail.com wrote:
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";
$db->query($sql);
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";
$db->query($sql);
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.

Thanks!
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.

Aug 14 '06 #2
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!

Aug 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Krista | last post: by
15 posts views Thread by Stat | last post: by
4 posts views Thread by Angelos | last post: by
4 posts views Thread by Steve | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.