Current location: Hot Scripts Forums » Programming Languages » PHP » Can't find error in sql syntax.


Can't find error in sql syntax.

Reply
  #1 (permalink)  
Old 06-03-05, 10:35 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Question Can't find error in sql syntax.

Hello,
I am having trouble finding the error in my SQL syntax. Here is what it says:
Quote:
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 'FROM nuke_bible WHERE Book = 'Deuteronomy' AND Chapter = '20''
Here is my code:
PHP Code:

mysql_query("SELECT Testament, Book, Chapter, Texta, Textb, Textc, $ID $TMID $VerseID FROM nuke_bible WHERE Book = '$book' AND Chapter = '$chapter'") or die(mysql_error()); 

I have tried everything that I know is possible to try. Please help. Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-04-05, 05:18 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I am suspecting the part $ID $TMID $VerseID!
print the query and show us the result.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-04-05, 07:09 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
$ID $TMID $VerseID

are these seperate variables? in which case it shud be...

$ID, $TMID, $VerseID
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-04-05, 03:24 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Here is the whole code so far. It was the only way I could think to do it. My point was if they selected ID checkbox then pull the column ID out. If not it won't print anything there so the sql_query does know that there was something there.

PHP Code:

 $VerseID $_POST['VerseID'];
 
$fontsize $_POST['fontsize'];
 
$fonttype $_POST['fonttype'];
 
$submit $_POST['Submit'];
 
 echo 
$book "<br>";        // For Debugging.
 
echo $chapter "<br>";        // For Debugging.
 
echo $ID "<br>";            // For Debugging.
 
echo $TMID "<br>";        // For Debugging.
 
echo $VerseID "<br>";        // For Debugging.
 
echo $fontsize "<br>";    // For Debugging.
 
echo $fonttype "<br>";    // For Debugging.
 
echo $submit "<br>";        // For Debugging.
 
 //**************************//
 //   Start Error Checking    //
 //**************************//
 
 
if($book == "Please select:") {
     echo (
"Please select a book.");
 }
 
 if(
$chapter == "") {
     echo (
"Please type a chapter.");
 }
 
//**********************//
 //  End Error Checking    //
 //**********************//
 
 
 //******************************************//
 //  Start Defining Variables for SQL query    //
 //******************************************//
 
 
if(isset($ID)) {
     
$ID "ID,";
 } else {
     
$ID '';
 }
 echo 
"<p>" "ID equals: " $ID "<br>";    // For Debugging.
 
 
if(isset($TMID)) {
     
$TMID "TMID,";
 } else {
     
$TMID "";
 }
 echo 
"TMID equals: " $TMID "<br>";        // For Debugging.
 
 
if(isset($VerseID)) {
     
$VerseID "VerseID,";
 } else {
     
$VerseID "";
 }
 echo 
"VerseID equals: " $VerseID "<br>";// For Debugging.
 //******************************************//
 //   End Defining Variables for SQL query    //
 //******************************************//
 
 
 //******************************************//
 // Start Defining Variables for Text Styles //
 //******************************************//
 
 
if($fonttype == "Arial") {
     
$fonttype "Arial, Helvetica, san-serif";
 } elseif(
$fonttype == "Times New Romans"){
     
$fonttype "Times New Roman, Times, serif";
 } elseif(
$fonttype == "Courier") {
     
$fonttype "Courier New, Courier, mono";
 } elseif(
$fonttype == "Georgia") {
     
$fonttype "Georgia, Times New Roman, Times";
 } elseif(
$fonttype == "Verada") {
     
$fonttype "Vernada, Arial, Helvetica, sans-serif";
 } elseif(
$fonttype == "Geneva") {
     
$fonttype "Geneva, Arial, Helvetica, sans-serif";
 }
 echo 
"Fonttype equals: " $fonttype "<br>";     // For Debugging.
 //******************************************//
 //  End Defining Variables for Text Styles     //
 //******************************************//
 
 
$user "root";
 
$pass "";
 
mysql_connect('localhost'$user$pass) or die(mysql_error());
 
mysql_query("SELECT Testament, Book, Chapter, Texta, Textb, Textc, $ID $TMID $VerseID FROM nuke_bible WHERE Book = '$book' AND Chapter = '$chapter'") or die(mysql_error()); 
I will be back with some more info in a bit.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-04-05, 04:02 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, done some more checking. If I remove those variables there is no diffrence. I still can't seem to understand why it is doing this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-05-05, 02:36 AM
Fallen Angel Fallen Angel is offline
New Member
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
You forgot to select your database.

Just add this after mysql_connect:


PHP Code:

mysql_select_db('my_database'); 

Also put commas after your variables : $ID, $TMID, $VerseID
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-06-05, 08:19 AM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
That doesn't fix that part though. The one I mentioned ^^^ there.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 06-14-05, 12:45 PM
KaraJ KaraJ is offline
New Member
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
You need to put quotes around your variable names, like this:

mysql_query("SELECT Testament, Book, Chapter, Texta, Textb, Textc, `$ID`, `$TMID`, `$VerseID` FROM nuke_bible WHERE Book = '$book' AND Chapter = '$chapter'") or die(mysql_error());

This gave me lots of trouble, but I finally found that you need to use the single quote on the tilde key (upper left on keyboard) when specifying tables to select from and the single quote on the double quote key (right hand side of keyboard) when specifying what to set the tables equal to. Hope this helps!

Kara
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
You have an error in your SQL syntax. Help! SevEre PHP 7 09-08-04 06:05 AM
SQL Syntax Question Daemon ASP 2 03-29-04 02:55 PM
Need Help on error in SQL syntax eric1328 PHP 1 02-14-04 01:08 AM
ERROR in SQL syntax near DATE_FORMAT() bitesize PHP 1 01-09-04 10:22 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 01:04 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.