heshan Posted September 8, 2012 Share Posted September 8, 2012 Hi All, I have a small problem related to a specific query. It creates following error. Unknown column 'attendance_state.state' in 'field list' $query="SELECT attendance_state.state,attendance_state.state_id from attendance_state inner join attendance on attendance_state.state_id=attendance.state_id where attendance.admission_no='".$admission_id[$i]."' and attendance.date='$date'"; $result=mysql_query($query) or die (mysql_error()); The table related to the query looks like this. "state_id" is set as auto increment field. attendance_state (state_id, state) attendance (admission_no, state_id, date) Link to comment https://forums.phpfreaks.com/topic/268162-problem-arises-in-a-sql-statement/ Share on other sites More sharing options...
Barand Posted September 8, 2012 Share Posted September 8, 2012 run the query "SHOW CREATE TABLE attendance_state" and post the result Link to comment https://forums.phpfreaks.com/topic/268162-problem-arises-in-a-sql-statement/#findComment-1376340 Share on other sites More sharing options...
heshan Posted September 9, 2012 Author Share Posted September 9, 2012 That query executed successfully...Following is the result.. Table Create Table attendance_state CREATE TABLE `attendance_state` ( `state_id` int(20) NOT NULL AUTO_INCREMENT, ` state` varchar(50) NOT NULL, KEY `state_id` (`state_id`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1 Link to comment https://forums.phpfreaks.com/topic/268162-problem-arises-in-a-sql-statement/#findComment-1376441 Share on other sites More sharing options...
Barand Posted September 9, 2012 Share Posted September 9, 2012 You have a space at the beginning of the " state" column name. Run ALTER TABLE `attendance_state` CHANGE COLUMN ` state` `state` VARCHAR(50) NOT NULL ; Link to comment https://forums.phpfreaks.com/topic/268162-problem-arises-in-a-sql-statement/#findComment-1376442 Share on other sites More sharing options...
heshan Posted September 9, 2012 Author Share Posted September 9, 2012 ohh yes exactly..thanks Barand.. Now it fixed and working... Link to comment https://forums.phpfreaks.com/topic/268162-problem-arises-in-a-sql-statement/#findComment-1376444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.