Page 1 of 1
what's wrong with my update statement?
Posted: Fri Mar 26, 2010 7:33 am
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.
Re: what's wrong with my update statement?
Posted: Fri Mar 26, 2010 11:29 am
by Christopher
Have you escaped all the values?
Re: what's wrong with my update statement?
Posted: Fri Mar 26, 2010 11:24 pm
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.
