I've a query in my php script

$result = mysql_query("SELECT State_Id FROM state_master WHERE State_Name='$statename'") or die(mysql_error());
$row=mysql_fetch_assoc($result);
return $row['State_Id'];

Which returns 23Unknown column 'State_Name' in 'where clause' where 23 is the correct state ID. What I'm doing wrong?

Is there any way to avoid the error and just to return the value?

I'm new in this so I hope someone will point out my stupid mistake.

up vote 2 down vote accepted

You need to run DESC state_master;. This will show you all the columns in that table.

Fine the correct column name for the state name. Evidently, from the error, it is not State_name. Then, use that correct column name in the SQL Statement.

If State_Name is the actual column name, then try lowercase on all column names

$result = mysql_query("SELECT state_Id FROM state_master WHERE state_name='$statename'") or die(mysql_error());
$row=mysql_fetch_assoc($result);
return $row['state_Id'];

Give it a Try !!!

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.