Jump to content

Update Sql Statement Creating Some Errors


real_illusions
 Share

Recommended Posts

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 1
There 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? Edited by real_illusions
Link to comment
Share on other sites

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 1
I 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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...