patternsqlMinor
Unknown column in 'where clause'
Viewed 0 times
unknownwhereclausecolumn
Problem
I've a query in my php script
Which returns
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.
$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.
Solution
You need to run
Fine the correct column name for the state name. Evidently, from the error, it is not
If
Give it a Try !!!
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 !!!
Code Snippets
$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'];Context
StackExchange Database Administrators Q#83397, answer score: 2
Revisions (0)
No revisions yet.