Jump to content

[SOLVED] MySQL Query - INSERT - Unknown column 'test' in 'where clause'


MasterACE14

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.