I have built an html form that is filled out in two steps- first by an administrator and then by the user. The code above shows the user part after the admin has already filled a few fields and hit submit. The php generates a link to another page that contains these 4 fields- name, designation, phone and date. The code above is supposed to add data to the database in the column name but its not working. Also I get a warning and a few notices about undefined variables and indexes
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\Program Files\xampp\htdocs\badger.php on line 211
Can anyone tell me whats the problem in the code? Is it the update statement? My connect.php has no error because the previous few fields filled by the admin are being saved. The phone field shows a 0, but the other 3 are empty. Urgent help will be much appreciated.
This is what it says. Could not run query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’ id=‘{7466FFB9-20FC-B4BD-E2D5-3DC6C1BAD403}’ WHERE projects.id=‘{D5DB5A4C-’ at line 1
I can’t figure out whats wrong with that though. Its a syntactical error. Whats wrong with the syntax? Can you help me with that? In the line of code I am updating the id to a new ID so that the page that the user sees is different from the page that the admin just filled out.
I tried both without the {} and tried tom8’s update_sql statement. Doesn’t work. Could not run query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘{5F4FA1CB-050D-A534-0383-0F8F8782FCE1}’‘’ at line 1
Its the value of the $new_id variable. Any other suggestions?
I don’t know if this will fix it or not, but I removed the and used ' and changed the "WHEREprojects.id`={$id}" part and removed the {} as maxdream01 suggested.
Oh ok, I got that. And tried it. It was showing the value of the variable id in double quotes. So basically the function I used to create the unique ID for every instance of the form had a variable with single quotes in it. Anyway, I removed that and there is no more MySQL syntax error. However, my data still doesn’t get saved back to the database. I tried trouble shooting, and removed the updating of id to $new_id but it still doesn’t work. Please see if you can help here is the code.
$update_sql = "UPDATE projects SET Name='$name' WHERE dex=$dex;";
echo $update_sql;
$update_result = mysql_query($update_sql);
mysql_free_result($update_result);
gives this output:
UPDATE projects SET Name=‘‘kbdsb’’ WHERE dex=‘{43D135BF-BE9E-8358-0213-0F8B5E8DD94E}’;
However, the name column in my database is not being updated. Its text type. Does the length matter?
Yeah actually there is an error. I used mysql_error(). Could not run query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘gkwde’’ WHERE dex=‘{71C50C85-E4F2-987A-833F-2B0F00B63224}’’ at line 1
But I can’t seem to figure out where I have added the extra set of single notes.
Which of the guid needs single quotes. I just removed them from $name and now everything’s getting saved. Thank you so much. Everything is working now. Except when I try to update the id. Can’t you update a field whose value you are using in the condition for the UPDATE-SET command. Should I write another UPDATE statement to update the id’s value to that of $new_id? Here’s the statement.
$update_sql = "UPDATE projects SET dex={$new_id}, Name=$name, Designation=$designation, Phone=$phone, Date=$date WHERE dex=$dex ";
echo $update_sql;
$update_result = mysql_query($update_sql);
if (!$update_result) {
echo 'Could not run query: ' . mysql_error();
exit;
This code gives the following error:
Could not run query: Unknown column ‘9A17’ in ‘field list’
Here’s what echo $update_sql returns:
UPDATE projects SET dex={B0EE358D-9A17-FE7A-089C-C7DD2E02A27D}, Name=‘bcksbkd’, Designation=‘blkcdsl’, Phone=6302732, Date=‘blkcsnl’ WHERE dex=‘{B1FD2661-1DB9-0778-8A1E-AEC8E4611B5D}’
So basically its a part of the $new_id that’s causing the error. But I don’t know why. Is there a problem in the create_guid function?
Thanks for all your help tom8, r937, maxdream01 and scout1idf. The form is working perfectly. The id is getting updated in my database, however it is not getting updated in the URL after the user submits the form. I don’t know if I should be bothered though lol. Thanks again. I’ll bother you guys again if I get stuck somewhere.