real_illusions Posted June 19, 2009 Share Posted June 19, 2009 Hi all,I'm making a custom built mini-cms system to update some of the content on some web pages. However, I've come across some problems in trying to update the current text. The following is part of the script, and deals with updating the database, and I believe is the part that is causing the error. $main_header = mysql_escape_string($_POST['header']);$sub_header = mysql_escape_string($_POST['subheader']);$top_content = mysql_escape_string($_POST['FCKeditor1']);$second_header = mysql_escape_string($_POST['secondheader']);$second_content = mysql_escape_string($_POST['FCKeditor2']);$pagename = mysql_escape_string($item);$query = "UPDATE website_pages SET top_content=".$top_content.", top_header=".$main_header.", top_subheader=".$sub_header.", second_header=".$second_header.", second_content=".$second_content." WHERE pagename=".$pagename."";mysql_query($query) or die(mysql_error()); The error is as follows: 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 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenea' at line 1There are no ' in the text and theres no obvious reason to me why it should cut it off at that point. I'm using fck editor to edit some of the text, would that affect it in some way? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2009 Share Posted June 19, 2009 Have you printed the entire query to see what you're telling the database to do? Keep in mind that you need to quote string values. Link to comment Share on other sites More sharing options...
real_illusions Posted June 19, 2009 Author Share Posted June 19, 2009 Eh?I've tried all sorts of combinations of quotes and none in the update query, but they either insert the variable name or come up with that error, in the same place each time. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2009 Share Posted June 19, 2009 So print the query out to see what it looks like. String values do need quotes. If you want to print the query out I'll show you what's wrong with it. Link to comment Share on other sites More sharing options...
real_illusions Posted June 19, 2009 Author Share Posted June 19, 2009 Ok, I've printed the query out and all looks fine. Any ' that are in there have a \ in front of them, but they dont appear till later on in the text after where it says: 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 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenea' at line 1I found another forum post that puts the query how it should be i think, so my query now looks like this - $query = "UPDATE website_pages SET ('".$top_content."' , '".$main_header."' , '".$sub_header."' , '".$second_header."' , '".$second_content."') WHERE pagename=('".$pagename."')"; But still the error remains. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2009 Share Posted June 19, 2009 Were you going to show me the query? That's the only thing that matters. It might look fine to you, but if it was fine it wouldn't have an error. Link to comment Share on other sites More sharing options...
real_illusions Posted June 19, 2009 Author Share Posted June 19, 2009 Result of $query = "UPDATE website_pages SET ('".$top_content."' , '".$main_header."' , '".$sub_header."' , '".$second_header."' , '".$second_content."') WHERE pagename=('".$pagename."')";print $query;mysql_query($query) or die(mysql_error()); UPDATE derbyshiresport_pages SET ('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sit amet lectus risus. Etiam in pulvinar augue. Fusce vitae turpis diam. Nunc sed turpis varius ligula vulputate dignissim. Vivamus nisi massa, mattis non aliquam vel, elementum a elit. Phasellus vitae eros at quam consectetur blandit.Nam tristique massa nec lacus facilisis ac fringilla massa volutpat. Proin ut justo ante, convallis imperdiet risus. In hac habitasse platea dictumst. Vestibulum dui purus, sagittis ut eleifend vitae, mattis id lorem. Proin at dolor leo.' , 'About Us' , 'What is This Page?' , 'News' , 'Aenean sit amet velit nisi, eget malesuada urna. Aenean nec mauris urna, vitae adipiscing lorem\r\nVision\r\nauris neque mi, varius sed faucibus quis, suscipit et velit.') WHERE pagename=('about')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 '('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sit amet lec' at line 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2009 Share Posted June 19, 2009 You were closer in the first SQL statement, this one is missing the column names. I'm not sure what the parens are doing there, you don't need those for UPDATE. UPDATE derbyshiresport_pages SET top_content='Lorem ipsum dolor ... at dolor leo.' , top_header='About Us' , top_subheader='What is This Page?' WHERE pagename='about' Link to comment Share on other sites More sharing options...
real_illusions Posted June 19, 2009 Author Share Posted June 19, 2009 Thanks..it works now..for some reason. I put the variables back into the update statement and it now works...no idea why..as i tried that before and it didnt work... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.