jim.davidson Posted March 13, 2013 Share Posted March 13, 2013 I get this error when trying to insert form data and don't know why Unknown column 'yes' in 'field list' The table has (4) columns committee_member_id, committee_id, member_id, and chairman Here's the code $MM_flag="MM_insert";if (isset($_POST[$MM_flag])) { if (empty($_POST['committee_id'])) { $error['committee'] = 'You must select a committee'; } else { $committee_id = $_POST['committee_id']; } if (empty($_POST['member_id'])) { $error['member'] = 'You must select a member'; } else { $member_id = $_POST['member_id']; } if (isset($_POST['chairman_group'])) { $chairman = $_POST['chairman_group']; } if (!$error) { // Assign the tag $insertSQL = sprintf("INSERT INTO committee_members (committee_id, member_id, chairman) VALUES (%s, %s, %s)", GetSQLValueString($committee_id, "int"), GetSQLValueString($member_id, "int"), GetSQLValueString($chairman, "txt")); mysql_select_db($database_racc, $racc); $Result1 = mysql_query($insertSQL, $racc) or die(mysql_error()); }} Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/275629-getting-error-when-trying-to-insert-data-from-form/ Share on other sites More sharing options...
AyKay47 Posted March 13, 2013 Share Posted March 13, 2013 Change the error handling a bit so you can see the actual statement: $Result1 = mysql_query($insertSQL, $racc) or die("Error: " . mysql_error() . "<br>Query: " . $insertSQL); and display the results of the above. Also, if you are expecting committee_id and member_id to contain integers, %d instead of %s should be passed to printf() Quote Link to comment https://forums.phpfreaks.com/topic/275629-getting-error-when-trying-to-insert-data-from-form/#findComment-1418489 Share on other sites More sharing options...
Barand Posted March 14, 2013 Share Posted March 14, 2013 ... and the one that is a string should be in quotes otherwise SQL will think it is a fieldname ... VALUES (%d, %d, '%s') Quote Link to comment https://forums.phpfreaks.com/topic/275629-getting-error-when-trying-to-insert-data-from-form/#findComment-1418492 Share on other sites More sharing options...
jim.davidson Posted March 14, 2013 Author Share Posted March 14, 2013 I found the error, it was this line GetSQLValueString($chair_man, "txt")); It needed to be this GetSQLValueString($chair_man, "text")); Quote Link to comment https://forums.phpfreaks.com/topic/275629-getting-error-when-trying-to-insert-data-from-form/#findComment-1418513 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.