ballhogjoni Posted July 3, 2007 Share Posted July 3, 2007 How can I check to see if a row exists in my db table? I get 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 '\'s Test Title' at line 1" This is the code I have below: <?php $index_page_title = $_POST['index_page_title']; if (!empty($index_page_title)) { $username="xxx"; $password="xxx"; $database="xxx"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); if (mysql_query('SELECT * FROM Title WHERE ID=1')) { mysql_query("UPDATE Title SET newTitle = .$index_page_title") or die(mysql_error()); echo 'you updated you title to '.$index_page_title; } else { mysql_query("INSERT INTO Title (newTitle) VALUES ($index_page_title)") or die(mysql_error()); } unset($index_page_title); } else { ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 3, 2007 Share Posted July 3, 2007 Did you not ask this same question last week? Take a look at mysql_num_rows. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 mysql_query("UPDATE Title SET newTitle = .$index_page_title") or die(mysql_error()); You have an extra "." and you need that data to be encapsulated in single quotes. <?php $index_page_title = $_POST['index_page_title']; if (!empty($index_page_title)) { $username="xxx"; $password="xxx"; $database="xxx"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); if (mysql_query('SELECT * FROM Title WHERE ID=1')) { mysql_query("UPDATE Title SET newTitle = '$index_page_title'") or die(mysql_error()); echo 'you updated you title to '.$index_page_title; } else { mysql_query("INSERT INTO Title (newTitle) VALUES ('$index_page_title')") or die(mysql_error()); } Quote Link to comment 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.