berry05 Posted December 18, 2008 Share Posted December 18, 2008 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 '1111''' at line 1 anyone knows what that means? i googled it but only found peoples problems about the same error. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/ Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 post your query? Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718405 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 $otherusername = "SELECT item FROM users_items WHERE username='$Username'"; Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718407 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 echo $otherusername Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718410 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 I find that this works better for me: $otherusername = "SELECT item FROM users_items WHERE username='".$Username."'"; Make sure that you check your spelling (field name, table name ... etc) and the variable $Username exists (it isn't actually $username) and it isn't empty or NULL. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718412 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 I find that this works better for me: $otherusername = "SELECT item FROM users_items WHERE username='".$Username."'"; Make sure that you check your spelling (field name, table name ... etc) and the variable $Username exists (it isn't actually $username) and it isn't empty or NULL. And how exactly does that work better? There was nothing wrong with the way it was before. Variables are parsed when they are put inside double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718418 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 ok i did what you guys told me to do and now i dont get a error which is good but no items show up in inventory... <?php session_start(); if(isset($_SESSION['otherusername'])){ $db=mysql_connect('localhost', 'root', ''); $res=mysql_select_db('textgame',$db) or die(mysql_error()); $otherusername = "SELECT item FROM users_items WHERE username='".$Username."'"; $res=mysql_query($otherusername)or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo $otherusername; } }else{ echo "Sorry your not a member please join us!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718419 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 echo $otherusername Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718420 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 i have that there dont i? Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718421 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 meaning echo to screen, copy and paste on the forum Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718423 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 well you were supposed to echo it and post what it printed, for debugging purposes. Putting it inside your while loop is not the most ideal place to do this, though it would serve the purpose. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718424 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 I find that this works better for me: $otherusername = "SELECT item FROM users_items WHERE username='".$Username."'"; Make sure that you check your spelling (field name, table name ... etc) and the variable $Username exists (it isn't actually $username) and it isn't empty or NULL. And how exactly does that work better? There was nothing wrong with the way it was before. Variables are parsed when they are put inside double quotes. they are also in single quotes inside the doubble quotes...don't know, old habbits are hard to get rid of Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718425 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 well you were supposed to echo it and post what it printed, for debugging purposes. Putting it inside your while loop is not the most ideal place to do this, though it would serve the purpose. nothing came out when i debugged it..i get no errors but the inventory doesnt show the item in my users_items table Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718427 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 <OT> $x = "one"; $string = "the number $x"; // output: the number one $string = "the number '$x'"; // output: the number 'one' $string = 'the number $x'; // output: the number $x $string = 'the number "$x"'; // output: the number "$x" </OT> well you were supposed to echo it and post what it printed, for debugging purposes. Putting it inside your while loop is not the most ideal place to do this, though it would serve the purpose. nothing came out when i debugged it..i get no errors but the inventory doesnt show the item in my users_items table Okay so you are telling me that when you do this: $otherusername = "SELECT item FROM users_items WHERE username='".$Username."'"; echo $otherusername; Nothing echoes out? Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718429 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 something echoed out SELECT item FROM users_items WHERE username='' Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718431 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 I don't see $Username set anywhere. is it supposed to be the $_SESSION['otherusername'] in place of $Username ? Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718432 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 i tried $_SESSION['otherusername'] and still got nothing in the inventory...ill try echoing it though.. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718434 Share on other sites More sharing options...
trq Posted December 18, 2008 Share Posted December 18, 2008 As I said yesterday berry, your missing the basics. Your going to be asking questions every five minutes at this rate. Read that book! Start to finish. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718435 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 ok ...i'll read the book...sorry man... btw when i switch $otherusername with this .$_SESSION['otherusername']. i get this echoed... SELECT item FROM users_items WHERE username='SELECT item FROM users_items WHERE username='1111''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 '1111''' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718439 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 ok ...i'll read the book...sorry man... btw when i switch $otherusername with this .$_SESSION['otherusername']. i get this echoed... SELECT item FROM users_items WHERE username='SELECT item FROM users_items WHERE username='1111''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 '1111''' at line 1 Show your code that makes that message appear. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718441 Share on other sites More sharing options...
trq Posted December 18, 2008 Share Posted December 18, 2008 Somehow you are storing your query in $_SESSION['otherusername'] not your actual username by the looks. Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718443 Share on other sites More sharing options...
twm Posted December 18, 2008 Share Posted December 18, 2008 try and see if anything different happens. <?php session_start(); if(isset($_SESSION['otherusername'])){ $db=mysql_connect('localhost', 'root', ''); $res=mysql_select_db('textgame',$db) or die(mysql_error()); $otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'"; $res=mysql_query($otherusername)or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo $otherusername; echo $row['item'] . "<BR />"; } }else{ echo "Sorry your not a member please join us!"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718445 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 part of my index2.php code...just the inventory part.. <?php session_start(); if(isset($_SESSION['otherusername'])){ $db=mysql_connect('localhost', 'root', ''); $res=mysql_select_db('textgame',$db) or die(mysql_error()); $otherusername = "SELECT item FROM users_items WHERE username='".$_SESSION['otherusername']."'"; echo $otherusername; $res=mysql_query($otherusername)or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo $row; } }else{ echo "Sorry your not a member please join us!"; } } ?> insert2.php code <?php //ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="textgame"; // Database name $tbl_name="users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $Username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE; $password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE; $password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE; if(!$Username) die('username not set'); if(!$password1) die('Password1 not set'); else $password1 = md5($password1); if(!$password2) die('Password2 not set'); else $password2 = md5($password2); $query = "SELECT * FROM users WHERE username='$Username' AND password1='$password1' AND password2='$password2'"; $result = mysql_query($query) or die( mysql_error()); $count=mysql_num_rows($result); if($count==1) { $otherusername = "SELECT item FROM users_items WHERE username='".$Username."'"; session_start(); //session_register("username"); $_SESSION['Username'] = $Username; $_SESSION['otherusername'] = $otherusername; $result1 = mysql_query($queryy); $row = mysql_fetch_assoc($result1); $_SESSION['gold'] = $row['gold']; //session_register("inventory"); $Query = "SELECT item FROM users_items WHERE username='$Username'"; $Result = mysql_query($Query); $Row = mysql_fetch_array($Result); $_SESSION['inventory'] = $Row['item']; header("location:index2.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718446 Share on other sites More sharing options...
berry05 Posted December 18, 2008 Author Share Posted December 18, 2008 i got rid of echo $otherusername; and it worked!! thank you!! and for thorpe i swear i'm going to start reading that book now!! thxs for all your help guys!! Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718450 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 use $_SESSION['Username'] in your query Quote Link to comment https://forums.phpfreaks.com/topic/137470-solved-sql-syntax-error/#findComment-718452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.