Qeury problem(plz help)

Reply

Join Date: Sep 2006
Posts: 10
Reputation: cty is an unknown quantity at this point 
Solved Threads: 0
cty cty is offline Offline
Newbie Poster

Qeury problem(plz help)

 
0
  #1
Dec 18th, 2006
Error message:

Query failed: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

--------------------------------------
Can any one able to edit it in correct form?(*I using PHP5)
----------------------------------------------


$[PHP]query="select count(*) from cart where cookieId ='GetCartId()'
and bookid = '$bookid'";[/PHP]
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 23
Reputation: DennisP is an unknown quantity at this point 
Solved Threads: 0
DennisP DennisP is offline Offline
Newbie Poster

Re: Qeury problem(plz help)

 
0
  #2
Dec 19th, 2006
Type the following after you declare the $query variable:

  1. echo $query;

You should then be able to debug your query. If not, post what you get here.
Simple PHP Pagination - No Database Required.
If you like it, give me some props. ;)
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 1
Reputation: joseph.hodali is an unknown quantity at this point 
Solved Threads: 0
joseph.hodali joseph.hodali is offline Offline
Newbie Poster

Re: Qeury problem(plz help)

 
0
  #3
Dec 20th, 2006
Originally Posted by cty View Post
Error message:

Query failed: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

--------------------------------------
Can any one able to edit it in correct form?(*I using PHP5)
----------------------------------------------


$[PHP]query="select count(*) from cart where cookieId ='GetCartId()'
and bookid = '$bookid'";[/PHP]
Hello cty ,

According to your SQL statement that is embeded in your PHP code, there is a very simple mistake which is : take a look at your SQL statement , the second condition in the WHERE Clause which is -
bookid = '$bookid'; - there has to be two dots , one before the $ sign in the variable and one after the variable , also there has to be double quotes before the single quotes, so it should look like this :
bookid = "'.$bookid.'";

So your query will be like this :

query="select count(*) from cart where cookieId ='GetCartId()'
and bookid = "'.$bookid.'" ";

So, please try it and see if it works , and please reply me whether it worked or not , because this was from my experience using PHP With MySQL ..

Hope it works well ..
looking forward for your reply ,

Best regards
Joseph.G.Hodali
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 33
Reputation: remcov is an unknown quantity at this point 
Solved Threads: 0
remcov remcov is offline Offline
Light Poster

Re: Qeury problem(plz help)

 
0
  #4
Dec 21st, 2006
Sorry joseph.hodali you are wrong. The bookid part is ok, except from the fact that he needs to user {$bookid} when using variables inside double quotes. The {} define the beginning and end of a varibale inside double quotes. This makes it possible to do [php]$string="{$array['id']} bla bla.";[/php]

The problem is the function GetCartId(), if its an sql function you don't use the single quotes, but I bet its an php function and you can not include a function inside a string. Try this it should function better.

[php]$cartId = GetCartId();
$query="select count(*) from cart where cookieId ='{$cartId}'and bookid = '{$bookid}'";[/php]
Last edited by remcov; Dec 21st, 2006 at 1:19 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC