MySQL Error

He has: 1,380 posts

Joined: Feb 2002

I'm getting an error in a php CMS I'm setting up...it says I have a MySQl error near " on line 1...

The way it works, is the user selects the page to edit content from...and then PHP brings the text out of the dB and prints it into text boxes. This part works fine.

And when the user hits submit to submit the changes, I get the error. This is the part that is confusing me:
[indent]The page in the location bar of the browser says its the page where the textboxes are, but all of the PHP and MySQL had already been executed. This makes me think its the next page, which updates the dB.[/indent]

Heres the only MySQL in the page:

<?php
/* Connect to database */
$dbh = mysql_connect (\"localhost\", \"...\", \"...\") or die('Database failure: ' . mysql_error());
$dbh2 = mysql_select_db (\"ttots_content\");

/* Update data */
$update = mysql_query(\"UPDATE $page SET header = '$header', body = '$body'\") or die(mysql_error());

/* Disconnect database */
mysql_close(
$dbh);
?>

See anything wrong with this? I cant seem to find anything! Thanks for any help

They have: 5,633 posts

Joined: Jan 1970

As much as I can tell .. you may want to make sure you call addslashes function on text fields that you want to insert or update fields. This way the " and ' characthers that can appear in the text will not affect your query.

Best regards,
Valentin Ciocea
CioceaSoft.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.