What's wrong with this?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

What's wrong with this?

Post by mjseaden »

Code: Select all

SELECT PropertyID FROM Bookmarks WHERE (PropertyID=4 && Username='XXXX')
For some reason this reports the error

Code: Select all

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 3
I cannot spot the error in this query - what is wrong?

Many thanks

Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

echo the query before you execute it to make sure it contains all the information you think it does

Mark
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi Bech

The output I've pasted onto my original message is copied from echoed output

Many thanks

Mark
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

lose the "( )" ?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Brackets are perfectly correct syntax.

Can you show a bit of the code.

Mark
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Well, you're right, in fact I copied the echoed statement and replaced the username with 'XXXXX' instead. Otherwise, you have my personal guarantee that it is indeed the echoed statement.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

hehehe, i edited my post before you replied.

Syntaxly (is that a word? It is now!), your statement is correct, so there must be some other problem. Post your code and ill take a look

Mark
Last edited by JayBird on Wed May 26, 2004 6:50 am, edited 1 time in total.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Code: Select all

$query2 = 'SELECT PropertyID FROM Bookmarks WHERE PropertyID='.$myarray[4].' && Username='''.$_SESSION['reg_user'].'''';
echo $query2;
$result2 = mysql_query( $query2 );

if(!$result2)
{
   do_html_header( 'Database Error', FALSE, 0 );
   do_html_message('Error - Could not perform MySQL query - '.mysql_error());
   do_html_footer();
   exit();
}
Many thanks
Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

so what happened when you took the brackets out, what error then?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Are you sure you have all caps right in your column names?
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi

I'm looking at the wrong error - I'm getting a problem with another query. Sorry for being a dufus, but often it's the simpler problems that can leave you scratching your head the most.

Thanks for the help - Mark.
Post Reply