473,320 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 6481

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Krista | last post by:
Hi, Hope you guys can help me out~~ I have a config.php file. I want to conncet to my own mysql version. When i run the config.php file as below, i get all successful message. However, when i take...
15
by: Stat | last post by:
Greetings all. I am writing a profile creator script where a user gets a URL invite in their mail in the form of; http://domain.com/profile-create.php?access_code=Ikd98jadf098asdf Things are...
4
by: Angelos | last post by:
Hello, First of all sorry if this is not the correct newsgroup for this question, but I am using PHP with MYSQL and someone here could have an answer and the experience. I have the a table...
1
by: McGowan | last post by:
Hey, I'm wondering how I can get an update statement to work with data being passed through the URL. the problem is that the statement needs to work no matter what table is being worked on as any...
1
by: jenson | last post by:
<?php /* * Created on Apr 13, 2007 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ require_once 'init.php'; ...
1
by: tromton | last post by:
hello all, ive been wondering latley if someone could change a get variable, so he can change a sql statement that way, that he could delete data from my database. the following ive thought of: ...
4
by: Steve | last post by:
Can someone help me with this code - I'm trying to retrieve updated product information by pulling 3 fields and inserting values into my MYSQL db. In my code below I'm getting the page but I can't...
9
by: chromis | last post by:
Hi, I've never coded in ASP before and I'm trying to port a couple of simple PHP files to ASP.NET. The first file addScores.php takes form data and a hash and inserts the data into the db, it...
1
by: ririe | last post by:
Hi. I have a problem here. I want to upload a file together with its semester. So I create two field. One for the semester and one for the file to be uploaded. But the script doesn't work. I don't...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.