Can't find error in sql syntax.
06-03-05, 10:35 PM
Newbie Coder
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
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:
I have tried everything that I know is possible to try. Please help. Thanks.
06-04-05, 05:18 AM
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 ]
06-04-05, 07:09 AM
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.
06-04-05, 03:24 PM
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.
06-04-05, 04:02 PM
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.
06-05-05, 02:36 AM
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:
Also put commas after your variables : $ID, $TMID, $VerseID
06-06-05, 08:19 AM
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.
06-14-05, 12:45 PM
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
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off