what's wrong with my update statement?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

what's wrong with my update statement?

Post by ramblin54321 »

Code: Select all

//take the regular variables and put them into the corresponding table field names prior to inserting into SQL
$sql = "UPDATE students SET last = '$last', first = '$first', gradeYear = '$gradeYear', streetAddress = '$streetAddress', cityState = '$cityState' WHERE id ='$id'";
 //insert posted entries into database table
$inserted = mysql_query($sql, $db) or die(mysql_error());
It worked for an INSERT INTO without the WHERE but UPDATE doesn't update the database. Maybe I have just been up too long working on this to see an easy fix. No errors came up and the data is in the variable with the dollar sign just can't get it to go into the database with this update statement. Help much appreciated.
Last edited by Benjamin on Fri Mar 26, 2010 4:00 pm, edited 1 time in total.
Reason: Changed code type from text to php
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: what's wrong with my update statement?

Post by Christopher »

Have you escaped all the values?
(#10850)
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

Re: what's wrong with my update statement?

Post by ramblin54321 »

Thanks for letting me know there was nothing wrong with the statement and to focus on the data and variables. I had a feeling it was something simple and just overlooked. Values didn't need to be escaped because the comma in a text field went through o.k.. Turns out I hadn't been using the i.d. variable in inserts because it was auto incremented and forgot to pass it as a variable needed for the update statement. :oops:
Post Reply