Edit: Now fixed! Thank you for your help!
Sorry for the beginner questions, I'm creating a simple page to edit another page for my teams website.
This is the code I'm using, but it's not updating the database.
Incorrect code:
mysql_query("UPDATE pages SET `pagename` = $pagename, `pagedesc` = $pagedesc,
`agekey` = $pagekey, `pagecont` = $pagecont WHERE `pages_id` = $pages_id") or die(mysql_error());
Correct code:
mysql_query("UPDATE pages SET pagename = '$pagename', pagedesc = '$pagedesc', pagekey = '$pagekey', pagecont = '$pagecont' WHERE pages_id = $pages_id") or die(mysql_error());
Using `` did not work at all. But adding or die(mysql_error()); to my query helped. I should have thought of that first! :)
Isn't your mysql query should be
mysql_query("UPDATE pages SET pagename = '$pagename', pagedesc = '$pagedesc', pagekey = '$pagekey', pagecont = '$pagecont' WHERE pages_id = $pages_id");
instead of
mysql_query("UPDATE pages SET 'pagename' = $pagename, 'pagedesc' = $pagedesc, 'pagekey' = $pagekey, 'pagecont' = $pagecont, WHERE 'pages_id' = $pages_id");
You were using ' (Single quote) in field name. single quote is used when the data is of type varchar
e.g. If table have field as myField02 varchar2(20), then while inserting query will be
INSERT INTO myTable values ('myValue');
If the field are not varchar then don't use single quote
INSERT INTO myTable values (myValue);
You have an extra "," in your SQL statement.
agecont, WHERE
Add this to the line which has mysql_query:
mysql_query("<QUERY GOES HERE>") or die(mysql_error());
This will show you the exact error in the query.
Your problem is that you are not checking whether your query is actually succesful or not. EDIT: Think you got this one.
There are a few syntax errors in your SQL query:
For Example
// Your code
UPDATE pages SET 'pagename' = $pagename
// How SQL expects
UPDATE pages SET pagename = '$pagename'
Notice the single quotes ONLY around the variables we want to put in.
Re-writing your SQL query:
mysql_query("UPDATE pages
SET pagename = '{$pagename}',
pagedesc = '{$pagedesc}',
agekey = '{$pagekey}',
pagecont = '{$pagecont}'
WHERE pages_id = '{$pages_id}'") or die(mysql_error());
Note the column names have no ` or ' surrounding them, only the variables you are using to run the update.
EDIT: Answer updated to show op where his errors are
mysql_query("UPDATE pages SET
pagename
= '$pagename',pagedesc
= '$pagedesc',pagekey
= '$pagekey',pagecont
= '$pagecont' WHEREpages_id
= $pages_id");
use `(accent) instead of ' in fields and u have extra ,(comma) before where
You have two errors in your query one the comma
before where and second you have used single quotes
for fieldnames. Use backtics instead of single quotes for fieldname. Use this query. Also take care of sql injections. use mysql_real_escape_string().
mysql_query("UPDATE pages SET `pagename` = $pagename, `pagedesc` = $pagedesc,
`agekey` = $pagekey, `pagecont` = $pagecont WHERE `pages_id` = $pages_id");