Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2004, 12:16 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default error 1064 SQL syntax puzzle

I'm getting an error message that i can't unclog:

Code:
1064 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 '' at line 1
this is the code snippet:

Code:
$result_projects = mysql_query("SELECT * FROM databasename.projects WHERE projects.path = $current_projectpath");

if(!$result_projects)
{
die("<p>".mysql_errno()." ".mysql_error()."</p>");
}
I've looked online through forums for a while, and can't figure out the cause. I've double checked everything within the query that i can think of, such as:

1. I've run the query from the command line in mySQL and it returns exactly what i want.

2. I've echoed all the variables used, and they're exactly as expected.

Any suggestions about where the syntax error is? Thanks.


Reply With Quote
  #2 (permalink)  
Old April 24th, 2004, 12:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Does the variable $current_projectpath contain the value of a field?

Also, I don't know if it will change anything, but try using functions like mysql_select_db instead of SELECTing from the database like you do. You don't need to include the name of the table when you refer to the field, either.

Let me know if these things help.

Snib

<><
Reply With Quote
  #3 (permalink)  
Old April 24th, 2004, 01:02 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

As suggested, I adjusted the code to:

Code:
mysql_select_db("databasename");
$result_projects = mysql_query("SELECT * FROM projects WHERE projects.path = $current_projectpath");
I'm still getting exactly the same error.

$current_projectpath contains the value to find in the "path" field of the table "projects". I've also tried substituting the actual value that $current_projectpath should be/is, and it made no difference.

Thanks for the help so far. Any other suggestions are appreciated.


Reply With Quote
  #4 (permalink)  
Old April 24th, 2004, 01:27 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

If $current_projectpath contains a value that you are looking for, you need to surround the variable in single quotes:

Code:
mysql_query("SELECT * FROM projects WHERE projects.path='$current_projectpath'");
Without the quotes, MySQL searches for a field named whatever $current_projectpath is (I think this is your problem).

Also, I'm not sure that it accepts whitespace around the equals sign (it might, I'm just not sure).

HTH,

Snib

<><
Reply With Quote
  #5 (permalink)  
Old April 24th, 2004, 06:31 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib - thank you !

That appears to have fixed the problem (and it seems that whitespace doesn't make a difference). One reason I was (and am) so confused is that the following snippet (from another part of the code) still works (and always has):

Code:
$result_projects = mysql_query("SELECT * FROM databasename.projects WHERE projects.CID=$c_ID")
where $c_ID is a variable holding the number to look up in the "CID" field of the "projects" table.

I wish I knew what's going on, but if it ain't broke, i'm not going to break it.

Thanks again.


Reply With Quote
  #6 (permalink)  
Old April 24th, 2004, 09:20 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I'm glad it's working. Thanks for letting me know about the whitespace.

Snib

<><
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in SQL syntax phantom3008 ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2007 07:00 AM
mysql #1064 error manahual MySQL 0 April 23rd, 2007 01:44 PM
Example SQL causes syntax error Tom Rigby BOOK: Beginning SQL 1 April 18th, 2007 09:32 AM
SQL Syntax Error I can't figure out Syster Tara Classic ASP Basics 24 December 2nd, 2006 05:09 PM
1064 error kennymain MySQL 0 July 16th, 2005 03:19 PM



All times are GMT -4. The time now is 01:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.