MasterACE14 Posted November 28, 2007 Share Posted November 28, 2007 Evening Everyone, I have a registration script on my website, and it was working fine, I added a second MySQL INSERT query to it, for another table so I can use JOIN's later on with the second table, but I keep getting the same error: Unknown column 'test' in 'where clause' can someone see whats wrong with this? here's the relevent code: <?php // SQL query to insert the players account into the database $sql = "INSERT INTO `cf_users` (money,username,email,password,race,neededexp,strikeaction,defenceaction,covertaction,level_strikeops,amount_strikeops,price_strikeops,level_defenceops,amount_defenceops,price_defenceops,level_covertops,amount_covertops,price_covertops) VALUES ('$money','$username','$email','$password_hashed','$race','$neededexp','$strike_action','$defence_action','$covert_action','$level_strikeops','$amount_strikeops','$price_strikeops','$level_defenceops','$amount_defenceops','$price_defenceops','$level_covertops','$amount_covertops','$price_covertops')"; // execute the query mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); // grab players id $sql_id = "SELECT `id` FROM `cf_users` WHERE username = $username;"; // execute the query $id_needed = mysql_query( $sql_id ) or die('Query:<br />' . $sql_id . '<br /><br />Error:<br />' . mysql_error()); $more_sql = "INSERT INTO `cf_users2` (id) VALUES ('$id_needed')"; // SQL query to insert the players ID into their other table mysql_query( $more_sql ) or die('Error:<br />' . mysql_error()); ?> Regards ACE Quote Link to comment Share on other sites More sharing options...
mrdamien Posted November 28, 2007 Share Posted November 28, 2007 // grab players id $sql_id = "SELECT `id` FROM `cf_users` WHERE username = $username;"; $username is not quoted so the query would turn out to be: SELECT `id` FROM `cf_users` WHERE username = test; Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 28, 2007 Author Share Posted November 28, 2007 sorry? here's my latest code: <?php // grab players id $sql_id = "SELECT `id` FROM `cf_users` WHERE username = $username LIMIT 1"; Quote Link to comment Share on other sites More sharing options...
elefant Posted November 28, 2007 Share Posted November 28, 2007 My understanding is that SQL queries cannot end with semicolons. http://us3.php.net/function.mysql-query Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 28, 2007 Author Share Posted November 28, 2007 I have removed that and still get the same :-\ Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 28, 2007 Share Posted November 28, 2007 What mrdamien was getting at is, because the username column is a string, you must put single-quotes around any data you are comparing it with. Otherwise, an unquoted string is treated as a column name, which is what the error is stating. In case that was not an explicit enough explanation, do the following - $sql_id = "SELECT `id` FROM `cf_users` WHERE username = '$username'"; The semi-colon inside of at the end of the sql statement is not required. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 28, 2007 Author Share Posted November 28, 2007 oh ok, its working now, Thanks guys, much appreciated Regards ACE Quote Link to comment 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.