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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.