Jump to content

INSERT issue


fife

Recommended Posts

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!";
}

?>

Link to comment
Share on other sites

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."')";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.