9 Replies - 833 Views - Last Post: 22 October 2008 - 05:26 PM Rate Topic: -----

#1 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

You have an error in your SQL syntax

Posted 22 October 2008 - 11:21 AM

mysql_query("insert into items(item, userid, user) values('".$itemname."', ".$_SESSION['id'].", '".$user."' ") or die (mysql_error());

thats the line that is the problem

this is the error im getting

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 'glass bottle'', 1, 'matty'' at line 1

not quite sure what is wrong with it

Is This A Good Question/Topic? 0
  • +

Replies To: You have an error in your SQL syntax

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3097
  • View blog
  • Posts: 10,883
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 11:48 AM

It looks to me like you're missing single quotes around $_SESSION['id']. Try it this way:
mysql_query("insert into items(item, userid, user) values('".$itemname."', '".$_SESSION['id']."', '".$user."' ") or die (mysql_error());

Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5929
  • View blog
  • Posts: 12,851
  • Joined: 16-October 07

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 11:49 AM

Missed a trailing ")" looks like:
"insert into items(item, userid, user) values('".$itemname."', ".$_SESSION['id'].", '".$user."')"
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3097
  • View blog
  • Posts: 10,883
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 11:53 AM

Oh, and I think you're confusing $query ="blah, blah..."; and mysql_query($query) with plain old mysql_query(your query here);
You're better off using $query ="blah, blah..."; so that you can echo the query to look for problems.
Was This Post Helpful? 0
  • +
  • -

#5 homemade-jam  Icon User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 12:27 PM

omg Baavgai, be ashamed of yourself! No code tags in your post?

This post has been edited by homemade-jam: 22 October 2008 - 12:27 PM

Was This Post Helpful? 0
  • +
  • -

#6 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 12:42 PM

										$mysql = "insert into items(item, userid, user) values('".$itemname."', '".$_SESSION['id']."', '".$user."')";
										mysql_query($mysql) or die (mysql_error());


i have done that however now i am getting

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

and i cant fic it :S i've done what you said to do

just incase its summit else
<?php 
							if(isset($_POST['buy'])){
										$itemname = $_POST['buy_items'];										
										$costofitem = mysql_query("select moneybad from itemstats where item = '".$itemname."') ") or die (mysql_error());
											$costofitem2 = mysql_fetch_array($costofitem);
												$sum = array_sum($costofitem2);
										mysql_query("update members set money = money - '".$sum."' where id = '".$_SESSION['id']."'") or die ("item can not be bought " . mysql_error());
										$name = mysql_query("select username from members where id = '".$_SESSION['id']."'") or die (mysql_error());
											$whatname = mysql_fetch_array($name);
												$user = $whatname['username'];	
										$mysql = "insert into items(item, userid, user) values('".$itemname."', '".$_SESSION['id']."', '".$user."')";
										mysql_query($mysql) or die (mysql_error());
										echo "you bought the ".$_POST['buy']." for $".$sum."";
										}
									
								$items = mysql_query("select item, moneybad from itemstats where item != 'scout tactical' and item != 'spas 12'") or die(mysql_error());													
								while($itemresults = mysql_fetch_array($items)){
									$item = $itemresults['item'];
									$cost = $itemresults['moneybad'];
										echo "
											<tr>
												<td>
												
													".$item."
												</td>
												<td>
													".$cost."
												</td>
												<td>													
													<form action=\"buyitems.php\" method='post'>
													<input type='radio' name='buy_items' value='".$item."'>													
												</td>
											</tr>
											";
								}
								echo "
									<tr>
										<td colspan='3'>
											<input type='submit' name='buy' value='buy!'
											</form>
										</td>
									</tr>
								</table>";
										
							?>

This post has been edited by ghqwerty: 22 October 2008 - 12:44 PM

Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3097
  • View blog
  • Posts: 10,883
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 12:56 PM

Try inserting an echo $mysql just before the mysql_query line. That way you can look at the query:
$mysql = "insert into items(item, userid, user) values('".$itemname."', '".$_SESSION['id']."', '".$user."')";
echo $mysql;
mysql_query($mysql) or die (mysql_error());


Maybe it's something with the value of $user.
Was This Post Helpful? 0
  • +
  • -

#8 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 01:06 PM

hmm

well i have added that in but its not even getting to it to echo it, it must be outside of the i(isset


edit

hmm wait - it would have to still be part of the if isset as it only appears after submitting the information

This post has been edited by ghqwerty: 22 October 2008 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#9 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 01:11 PM

i have sussed it :)

$costofitem = mysql_query("select moneybad from itemstats where item = '".$itemname."') ")

look carefully
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3097
  • View blog
  • Posts: 10,883
  • Joined: 08-August 08

Re: You have an error in your SQL syntax

Posted 22 October 2008 - 05:26 PM

;)
Extra: )
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1