DBookatay Posted November 23, 2008 Share Posted November 23, 2008 I've been struggling with (what I thought was) a simple query, but I keep getting this error: 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 '( logo, last_updated ) VALUES ( 'Default', '2008-19-11' )' at line 1 The query is: if ($_POST['edit']) { $logo = $_POST['logo']; $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1']; mysql_query(" UPDATE Website SET (logo, last_updated) VALUES ('$logo', '$updated')" )or die(mysql_error()); echo "<meta http-equiv=\"Refresh\" content=\"0; url=edit.php?category=Logos\">";} The query works with just the "logo", but once I add the "updated" values I throw an error. I've tried with the DB field as date and as varchar and continue to get the error. Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/ Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 try removing the word SET, if that doesn't fix it echo out the query and post it here Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696801 Share on other sites More sharing options...
DBookatay Posted November 23, 2008 Author Share Posted November 23, 2008 try removing the word SET, if that doesn't fix it echo out the query and post it here Removing SET didnt work... What am I supposed to do now, I didnt understand the second part of your post. Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696803 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 something like if ($_POST['edit']) { $logo = $_POST['logo']; $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1']; $query = "UPDATE Website (logo, last_updated) VALUES ('$logo', '$updated')"; mysql_query($query)or die(mysql_error());} Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696806 Share on other sites More sharing options...
DBookatay Posted November 23, 2008 Author Share Posted November 23, 2008 something like if ($_POST['edit']) { $logo = $_POST['logo']; $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1']; $query = "UPDATE Website (logo, last_updated) VALUES ('$logo', '$updated')"; mysql_query($query)or die(mysql_error());} Copied and pasted your code exactly and got this error: 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 '(logo, last_updated) VALUES ('Default', '2008-19-11')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696807 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 oops, I'm sorry. if ($_POST['edit']) { $logo = $_POST['logo']; $updated = '20'.$_POST['lstUpdte3'].'-'.$_POST['lstUpdte2'].'-'.$_POST['lstUpdte1']; $query = "UPDATE Website (logo, last_updated) VALUES ('$logo', '$updated')"; echo $query; mysql_query($query)or die(mysql_error());} though the error message kind of shows us what we need to know... Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696809 Share on other sites More sharing options...
dropfaith Posted November 23, 2008 Share Posted November 23, 2008 use tis but on a side note i thought you needed a where statement to edit im kinda newish with update so please correct me if im wrong but this code below works for me $query = "UPDATE Website SET logo = '$logo', last_updated = '$updated'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); echo $query; Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696810 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 Jeeze dropfaith, you're right... that was such a stupid mistake on my part not to notice that. Op: do you mean to be doing INSERT INTO? Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696811 Share on other sites More sharing options...
DBookatay Posted November 23, 2008 Author Share Posted November 23, 2008 Ok, this is what I got: UPDATE Website (logo, last_updated) VALUES ('Default', '2008-19-11')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 '(logo, last_updated) VALUES ('Default', '2008-19-11')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696813 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 When you edit a column you have to set a WHERE param. UPDATE Website SET logo = '$logo', last_updated = '$updated' WHERE something='something' thanks, dropfaith, for slapping the back of my head on that one. Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696816 Share on other sites More sharing options...
dropfaith Posted November 23, 2008 Share Posted November 23, 2008 http://www.tizag.com/mysqlTutorial/mysqlupdate.php your telling it to update but not what to update that link is a tutorial on update but my code will work if you add a where cluase do you have an id on this table or anything you can reference as the where ? $query = "UPDATE Website SET logo = '$logo', last_updated = '$updated' WHERE FIELDNAME='SOMETHING'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); echo $query; haha np on the head slap its the whole extra set of eyes that code looked so different from mine i was like whao and noticed that it didnt have one Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696818 Share on other sites More sharing options...
DBookatay Posted November 23, 2008 Author Share Posted November 23, 2008 When you edit a column you have to set a WHERE param. UPDATE Website SET logo = '$logo', last_updated = '$updated' WHERE something='something' thanks, dropfaith, for slapping the back of my head on that one. WOW, I feel like a REAL iddiot!!! Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696819 Share on other sites More sharing options...
dropfaith Posted November 23, 2008 Share Posted November 23, 2008 oh and removing set kills the update statement hence this update DATABASE SET this to this set is what changes the info all update really did was choose the db name Quote Link to comment https://forums.phpfreaks.com/topic/133864-solved-for-the-life-of-me-update-query-problem/#findComment-696820 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.