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 { ?> Link to comment https://forums.phpfreaks.com/topic/58240-mysql-syntax-error/ 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. Link to comment https://forums.phpfreaks.com/topic/58240-mysql-syntax-error/#findComment-288751 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()); } Link to comment https://forums.phpfreaks.com/topic/58240-mysql-syntax-error/#findComment-288795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.