DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   MySQL syntax error 1064 (http://www.daniweb.com/forums/thread115918.html)

kevin wood Mar 27th, 2008 5:47 am
MySQL syntax error 1064
 
why i am i getting this synyax error when trying to display data from the database

the code for saving the data is

// save content to db
if(isset($_POST["inpContent"]))
        {
       
        $sContent=stripslashes($_POST['inpContent']); // remove slashes (/)       
        $sContent=ereg_replace("'","''",$sContent); // fix SQL
               
        $sql="UPDATE cms_core SET editorial='$sContent' WHERE id=$id";
        $query = mysql_query($sql);
        }

and the code to get the data from the data base is

$SQL = "SELECT cms_core FROM '$sContent' WHERE id=1";
 $res = mysql_query( $SQL, $db )
 or die( "<br><br><b>MySQL
 Error:</b> " . mysql_errno() . " // " .
 mysql_error() . "<br><br>" );

 if( $res !== "" ) {
 echo "Nothing in recordset.";
 } else {
 echo "Something in recordset.";
 }
thanks if anyone can help

RoryGren Mar 27th, 2008 6:04 am
Re: MySQL syntax error 1064
 
Hi Kevin

What else does the error message say?

Normally something along the lines of "near..."

kevin wood Mar 27th, 2008 6:11 am
Re: MySQL syntax error 1064
 
here is the full error message

MySQL Error: 1064 // You have an error in your SQL syntax near '' at line 1

RoryGren Mar 27th, 2008 7:21 am
Re: MySQL syntax error 1064
 
OK. A little hazy still ... We don't know which is line 1.

Print out your queries with
 echo $SQL 
and see if that helps.

nav33n Mar 27th, 2008 7:23 am
Re: MySQL syntax error 1064
 
Syntax error while updating the record or while fetching ?

Quote:

$SQL = "SELECT cms_core FROM '$sContent' WHERE id=1";
Quote:

$sql="UPDATE cms_core SET editorial='$sContent' WHERE id=$id";
cms_core ? is it a table or a column name ?

RoryGren Mar 27th, 2008 7:31 am
Re: MySQL syntax error 1064
 
Maybe my reply was a little hazy too! Sorry! ;-)

By printing out the queries, you will be able to see what the mySQL server is being sent and hopefully that will steer you in the right direction!

kevin wood Mar 27th, 2008 7:44 am
Re: MySQL syntax error 1064
 
i am no getting a different problem with error codes. cmsservdb is the database cms_core is the table name and editorial is the coloum name. my database sewtup looks like this

<?php
$db = mysql_connect("xxxxxxxx","xxxxx","xxxx");
mysql_select_db("cmsservdb", $db);

// Create table in my_db database
mysql_select_db("cmsserdb");
$sql = "CREATE TABLE cme_core
(
editroial longblob
)";
mysql_query($sql);

?>

and the error message i am getting now on the page that is recalling the data is

MySQL Error: 1146 // Table 'cmsservdb.editroial' doesn't exist

the code used to access this data is

 $SQL = "SELECT * FROM editorial WHERE id= 1 ";
 $res = mysql_query( $SQL, $db )
 or die( "<br><br><b>MySQL
 Error:</b> " . mysql_errno() . " // " .
 mysql_error() . "<br><br>" );

 if( $res !== "" ) {
 echo "Nothing in recordset.";
 } else {
 echo "Something in recordset.";
 }

kevin wood Mar 27th, 2008 7:49 am
Re: MySQL syntax error 1064
 
i have just edited the code used to recall the data so it looks like this and the error has gone it now tells me there is nothing in the record set.

the code looks like this

 $SQL = "SELECT editorial FROM cms_core WHERE id= 1 ";
 $res = mysql_query( $SQL, $db )
 or die( "<br><br><b>MySQL
 Error:</b> " . mysql_errno() . " // " .
 mysql_error() . "<br><br>" );

 if( $res !== "" ) {
 echo "Nothing in recordset.";
 } else {
 echo "Something in recordset.";
 }

nav33n Mar 27th, 2008 8:03 am
Re: MySQL syntax error 1064
 
$res will have the resource_id of the query you just executed. You can check if there are any records or not this way.
$res = mysql_query($SQL,$db);
if(mysql_num_rows($res) > 0){
echo "There is something!";
} else {
echo "Nothing !";
}

kevin wood Mar 27th, 2008 8:07 am
Re: MySQL syntax error 1064
 
i echoed the $sql on both the pages and on the page where the data is being recall it gave the


Nothing in recordset.CREATE TABLE cms_core ( editroial longblob id int )

and when i echoed the $sql on the page where it is saving it gave me


UPDATE cms_core SET editorial='

then all the text that is being saved to the database with

WHERE id=$id

after the text.

it looks like the data is being saved to the database but why can i not recall the data on the other page.


All times are GMT -4. The time now is 3:15 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC