MySQL syntax error 1064

Thread Solved

Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

MySQL syntax error 1064

 
0
  #1
Mar 27th, 2008
why i am i getting this synyax error when trying to display data from the database

the code for saving the data is

  1. // save content to db
  2. if(isset($_POST["inpContent"]))
  3. {
  4.  
  5. $sContent=stripslashes($_POST['inpContent']); // remove slashes (/)
  6. $sContent=ereg_replace("'","''",$sContent); // fix SQL
  7.  
  8. $sql="UPDATE cms_core SET editorial='$sContent' WHERE id=$id";
  9. $query = mysql_query($sql);
  10. }

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

  1. $SQL = "SELECT cms_core FROM '$sContent' WHERE id=1";
  2. $res = mysql_query( $SQL, $db )
  3. OR die( "<br><br><b>MySQL
  4. Error:</b> " . mysql_errno() . " // " .
  5. mysql_error() . "<br><br>" );
  6.  
  7. if( $res !== "" ) {
  8. echo "Nothing in recordset.";
  9. } ELSE {
  10. echo "Something in recordset.";
  11. }
thanks if anyone can help
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: MySQL syntax error 1064

 
0
  #2
Mar 27th, 2008
Hi Kevin

What else does the error message say?

Normally something along the lines of "near..."
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: MySQL syntax error 1064

 
0
  #3
Mar 27th, 2008
here is the full error message

MySQL Error: 1064 // You have an error in your SQL syntax near '' at line 1
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: MySQL syntax error 1064

 
0
  #4
Mar 27th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: MySQL syntax error 1064

 
0
  #5
Mar 27th, 2008
Syntax error while updating the record or while fetching ?

$SQL = "SELECT cms_core FROM '$sContent' WHERE id=1";
$sql="UPDATE cms_core SET editorial='$sContent' WHERE id=$id";
cms_core ? is it a table or a column name ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: MySQL syntax error 1064

 
0
  #6
Mar 27th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: MySQL syntax error 1064

 
0
  #7
Mar 27th, 2008
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

  1. <?php
  2. $db = mysql_connect("xxxxxxxx","xxxxx","xxxx");
  3. mysql_select_db("cmsservdb", $db);
  4.  
  5. // CREATE TABLE IN my_db database
  6. mysql_select_db("cmsserdb");
  7. $sql = "CREATE TABLE cme_core
  8. (
  9. editroial longblob
  10. )";
  11. mysql_query($sql);
  12.  
  13. ?>

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

  1. $SQL = "SELECT * FROM editorial WHERE id= 1 ";
  2. $res = mysql_query( $SQL, $db )
  3. OR die( "<br><br><b>MySQL
  4. Error:</b> " . mysql_errno() . " // " .
  5. mysql_error() . "<br><br>" );
  6.  
  7. if( $res !== "" ) {
  8. echo "Nothing in recordset.";
  9. } ELSE {
  10. echo "Something in recordset.";
  11. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: MySQL syntax error 1064

 
0
  #8
Mar 27th, 2008
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

  1. $SQL = "SELECT editorial FROM cms_core WHERE id= 1 ";
  2. $res = mysql_query( $SQL, $db )
  3. OR die( "<br><br><b>MySQL
  4. Error:</b> " . mysql_errno() . " // " .
  5. mysql_error() . "<br><br>" );
  6.  
  7. if( $res !== "" ) {
  8. echo "Nothing in recordset.";
  9. } ELSE {
  10. echo "Something in recordset.";
  11. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: MySQL syntax error 1064

 
0
  #9
Mar 27th, 2008
$res will have the resource_id of the query you just executed. You can check if there are any records or not this way.
  1. $res = mysql_query($SQL,$db);
  2. if(mysql_num_rows($res) > 0){
  3. echo "There is something!";
  4. } else {
  5. echo "Nothing !";
  6. }
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: MySQL syntax error 1064

 
0
  #10
Mar 27th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC