Mysql statement is throwing error.. why?

Thread Solved

Join Date: Jun 2009
Posts: 10
Reputation: BrettOwnz is an unknown quantity at this point 
Solved Threads: 0
BrettOwnz BrettOwnz is offline Offline
Newbie Poster

Mysql statement is throwing error.. why?

 
0
  #1
Jun 23rd, 2009
Hey guys..

I have been trying to debug this mysql statement for the past 2 hours.. here is the statement:

  1. $sql1 = "SELECT * FROM cpmip WHERE adid='$a' and ip='$ip'";
  2. $res1 = mysql_query($sql1) or die(mysql_error());

I just can't figure out why this won't work.. it throws the following error:

  1. 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 cpmip WHERE ip='127.0.0.1' and adid='6'' at line 1

Its really a vague error.. so i can't tell.. Anyone else know whats wrong??

Thanks in advance,
-Brett
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Mysql statement is throwing error.. why?

 
0
  #2
Jun 23rd, 2009
Do you have more than one SQL query?
In an error, MySQL will echo the query, but in the error you posted the ip and adid values are swapped.

I can't see anything wrong with your code there.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 10
Reputation: BrettOwnz is an unknown quantity at this point 
Solved Threads: 0
BrettOwnz BrettOwnz is offline Offline
Newbie Poster

Re: Mysql statement is throwing error.. why?

 
0
  #3
Jun 24th, 2009
Yes, there are many queries in this particular file.. BUT none of them have the same syntax as this one.. This is the only line that has adid and ip in it. I have no clue why i am getting this error now.. its really annoying...


Does anyone see something wrong/know what can be happening???

Thanks for the suggestion!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,634
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 471
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Mysql statement is throwing error.. why?

 
0
  #4
Jun 24th, 2009
>I have been trying to debug this mysql statement for the past 2 hours.. here is the statement:

  1. $sql1 = "SELECT * FROM cpmip WHERE adid='$a' and ip='$ip'";
  2. $res1 = mysql_query($sql1) or die(mysql_error());

> it throws the following error:

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 cpmip WHERE ip='127.0.0.1' and adid='6'' at line 1.

This error message is not belong to the select query you specified. Please post your complete code.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 10
Reputation: BrettOwnz is an unknown quantity at this point 
Solved Threads: 0
BrettOwnz BrettOwnz is offline Offline
Newbie Poster

Re: Mysql statement is throwing error.. why?

 
0
  #5
Jun 24th, 2009
After further investigation.. i looked at one of my functions and noticed it was actually in there.. however, this is still the same exact query except reversed... i don't see any errors with it.. do you??

  1. $sql = "SELECT * FROM cpmip WHERE ip='$ip' and adid='$a'";
  2. $res = mysql_query($sql) or die(mysql_error());

Thanks in advance,
-Brett
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,634
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 471
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Mysql statement is throwing error.. why?

 
0
  #6
Jun 24th, 2009
Will you post your complete code?
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 10
Reputation: BrettOwnz is an unknown quantity at this point 
Solved Threads: 0
BrettOwnz BrettOwnz is offline Offline
Newbie Poster

Re: Mysql statement is throwing error.. why?

 
0
  #7
Jun 24th, 2009
Ok.. here is the full function where this query occurs. Sorry for not wanting to post the whole thing, i just don't feel comfortable with that lol.. anyways heres the code.

  1. function mcheckTime($ip,$a){
  2. $myDb = new myDb;
  3. $myDb->connect();
  4. $sql = "SELECT * FROM cpmip WHERE ip='$ip' and adid='$a'";
  5. $res = mysql_query($sql) or die(mysql_error());
  6. $row = mysql_fetch_array($res);
  7. $myDb->close();
  8.  
  9. $time = time();
  10.  
  11. if($time >= $row['time']){
  12.  
  13. $myDb->connect();
  14. $sql1 = "DELETE * FROM cpmip WHERE ip='$ip' and adid='$a'";
  15. $res1 = mysql_query($sql1) or die(mysql_error());
  16. $myDb->close();
  17.  
  18. return true;
  19. }elseif($time < $row['time']){
  20.  
  21. return false;
  22. }}
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,634
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 471
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Mysql statement is throwing error.. why?

 
0
  #8
Jun 24th, 2009
Here is a problem:

$sql1 = "DELETE * FROM cpmip WHERE ip='$ip' and adid='$a'";

  1. $sql1 = "DELETE FROM cpmip WHERE ip='$ip' and adid='$a'";
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 10
Reputation: BrettOwnz is an unknown quantity at this point 
Solved Threads: 0
BrettOwnz BrettOwnz is offline Offline
Newbie Poster

Re: Mysql statement is throwing error.. why?

 
0
  #9
Jun 24th, 2009
Thank you.. that fixed that problem!! Now i am just having one problem.. another syntax error i didn't notice. Here is the code for the few lines surrounding it and it is highlighted. Just the same check your syntax error.

  1. if($num<1){
  2. $time = time() + (1 * 24 * 60 * 60);
  3. $sql2 = "INSERT INTO cpmip(adid,ip,time) VALUES('$a','$ip','$time')";
  4. $res2 = mysql_query($sql2) or die(mysql_error());
  5. if($row3['credits']<=0){
  6. $sql3 = "UPDATE cpm SET credits=0, active=0 WHERE id='$a'";
  7. $res3 = mysql_query($sql3) or die(mysql_error());
  8. }else{
  9. $sql4 = "UPDATE cpm SET views=views+1, credits=credits-1 WHERE id='$a'";
  10. $res4 = mysql_query($sql4) or die(mysql_error());
  11. $sql5 = "UPDATE user SET balance=balance+ WHERE userid='$u'";
  12. $res5 = mysql_query($sql5) or die(mysql_error());
  13. }}elseif($num==1){
  14. $a = mcheckTime($ip,$a);
  15. if($a==true){
  16. $time = time() + (1 * 24 * 60 * 60);
  17. $sql6 = "INSERT INTO cpmip(ip,adid,time) VALUES('$ip','$a','$time')";
  18. $res6 = mysql_query($sql6) or die(mysql_error());
  19. if($row3['credits']<=0){
  20. $sql7 = "UPDATE cpm SET credits=0, active=0 WHERE id='$a'";
  21. $res7 = mysql_query($sql7) or die(mysql_error());
  22. }else{
  23. $sql8 = "UPDATE cpm SET views=views+1, credits=credits-1 WHERE id='$a'";
  24. $res8 = mysql_query($sql8) or die(mysql_error());
  25. $sql9 = "UPDATE user SET balance=balance+0.00007 WHERE userid='$u'";
  26. $res9 = mysql_query($sql9) or die(mysql_error());
  27. }}elseif($a==false){}}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 10
Reputation: BrettOwnz is an unknown quantity at this point 
Solved Threads: 0
BrettOwnz BrettOwnz is offline Offline
Newbie Poster

Re: Mysql statement is throwing error.. why?

 
0
  #10
Jun 24th, 2009
Nevermind.. i was wrong i didn't notice it said balance+ and i never filled something in

My bad. Thanks for the help!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC