MooseBass Posted August 8, 2014 Share Posted August 8, 2014 Hi there. I'm totally new (about a week!) with php and mysql and am encountering a problem that perhaps someone can help me with? I've looked through to see if a similar problem has appeared or been solved, but without success, so apologies if I am repeating something. In php I am trying to update 7 fields from a form from which a user has edited/modified any of the fields in a chosen record (except id). Here is the code: $id=$_GET['id']; $task=$_POST['task']; $category=$_POST['category']; $created=$_POST['created']; $state=$_POST['state']; $due=$_POST['due']; $repeat=$_POST['repeat']; $completed=$_POST['completed']; mysql_select_db($database) or die( "Unable to select database for updating"); mysql_query("UPDATE tasks SET Task='$task',Category='$category', Status='$state', Created='$created', Due='$due',Completed='$completed', Repeat='$repeat' WHERE id = '$id'"); mysql_close(); No updating of any field occurs, so after playing around a bit I found that if I removed the Repeat section everything (except repeat of course) was updated successfully : mysql_query("UPDATE tasks SET Task='$task',Category='$category', Status='$state', Created='$created', Due='$due',Completed='$completed' WHERE id = '$id'"); I also added: echo "$repeat"; at the end and that shows that the variable $repeat does contain the new value from the form. Adding another update query: mysql_query("UPDATE tasks SET Repeat='$repeat' WHERE id = '$id'"); resulted in the repeat field not being updated. Any thoughts? Quote Link to comment Share on other sites More sharing options...
fastsol Posted August 8, 2014 Share Posted August 8, 2014 "Repeat" is a mysql reserved keyword. You need to wrap your table column names in `backticks` (the key to the left of the 1 on the keyboard). Backticks tell the query that what's between them is not to be considered a reserve word. Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted August 8, 2014 Solution Share Posted August 8, 2014 (edited) Please don't use backticks. We've discussed this multiple times, and the bottom line is: Backticks are harmful. In addition to that, you'd have to add them every single time you access the column, and if you ever forget it, you'll again wonder what the hell is wrong. The solution is to not use reserved words as identifiers. Edited August 8, 2014 by Jacques1 Quote Link to comment Share on other sites More sharing options...
MooseBass Posted August 8, 2014 Author Share Posted August 8, 2014 Many thanks fastsol & Jaquest, problem solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.