Jump to content

Mysql Syntax error!


ballhogjoni

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.