fife Posted July 27, 2010 Share Posted July 27, 2010 Hello. Like many posts on here i will start mine with "i'm new to php" I've just created my first ever script to insert rows from a form into the database but i keep getting this error Column count doesn't match value count at row 1 here is my code please can some point out the error of my ways; <?php include('the database name'); session_start(); $validation_id = strval(time()); if(isset($_POST['submit'])) { $first_name = mysql_real_escape_string($_POST['first_name']); $last_name = mysql_real_escape_string($_POST['last_name']); $DOB = mysql_real_escape_string($_POST['DOB']); $sex = mysql_real_escape_string($_POST['sex']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $agree = mysql_real_escape_string($_POST['agreed']); $creation_date = mysql_real_escape_string($_POST['creation_date']); $user_type = mysql_real_escape_string($_POST['member_type']); $access_level = mysql_real_escape_string($_POST['access_level']); $validation = mysql_real_escape_string($_POST['validation_id']); $club_user = mysql_real_escape_string($_POST['user_type']); $insert_member= "INSERT INTO Members (`first_name`,`last_name`,`DOB`,`sex`,`email`,`username`,`password`,`agree`,`creation_date`,`member_type`,`access_level`,`validationID`) VALUES ('".$first_name."','".$last_name."','".$DOB."','".$sex."','".$email."','".$username."','".$password."','".$agree."','".$creation_date."','".$user_type."''".$access_level."', '".$validation."')"; $insert_member_now= mysql_query($insert_member) or die(mysql_error()); echo "ENTERED INFORMATION FINE!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209029-insert-issue/ Share on other sites More sharing options...
RussellReal Posted July 27, 2010 Share Posted July 27, 2010 you if you have X amount of field names you need that same amount of values for example INSERT INTO table (field1,field2) VALUES (value1, value2) if they don't match you get that error Quote Link to comment https://forums.phpfreaks.com/topic/209029-insert-issue/#findComment-1091773 Share on other sites More sharing options...
Alex Posted July 27, 2010 Share Posted July 27, 2010 This error occurs when the number of provided column names does not match the number of values provided. In your case you're missing a comma between $user_type and $access_level. $insert_member= "INSERT INTO Members (`first_name`,`last_name`,`DOB`,`sex`,`email`,`username`,`password`,`agree`,`creation_date`,`member_type`,`access_level`,`validationID`) VALUES ('".$first_name."','".$last_name."','".$DOB."','".$sex."','".$email."','".$username."','".$password."','".$agree."','".$creation_date."','".$user_type."', '".$access_level."', '".$validation."')"; Quote Link to comment https://forums.phpfreaks.com/topic/209029-insert-issue/#findComment-1091774 Share on other sites More sharing options...
fife Posted July 27, 2010 Author Share Posted July 27, 2010 thank you both. I could not see that was missing. Quote Link to comment https://forums.phpfreaks.com/topic/209029-insert-issue/#findComment-1091775 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.