SQL Error: Column count doesn't match value count at row 1

I have made a registration form that was previously working fine, however after some changes in my code I have error "Error: Column count doesn't match value count at row 1"

<?php
$host = "localhost";
$user = "root";
$db_name= "login_stock";
$pass= "usbw";

$con = mysql_connect($host, $user, $pass);

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("login_stock", $con);
$name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file
$password=mysql_real_escape_string($_POST['password']); //This value has to be the same as in the HTML form file
$sql="INSERT INTO member_login (id,Name,Password, Allowance) VALUES (NULL,'$name','$password, 100000')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "The form data was successfully added to your database.";
mysql_close($con);
?>

id within the database is an auto incrementing int and a primary key. However the user is not required to enter their ID when they register.

What is considered the best way to fix this error!

Thanks in advanced!

Answers


Other than an erroneous ', you could just drop id from the column list:

INSERT INTO member_login (Name,Password, Allowance) VALUES ('$name','$password', 100000)

You should stop using mysql_ functions and use prepared statements to prevent against SQL injections.


INSERT INTO member_login (id,Name,Password, Allowance) 
VALUES (NULL,'$name','$password, 100000');

...only has 3 values (the third being the string '$password, 100000'). What you mean is probably to quote the password only;

INSERT INTO member_login (id,Name,Password, Allowance) 
VALUES (NULL,'$name','$password', 100000);

Need Your Help

control actions and urls in yii

url yii action

I am trying to perform different actions stored in the same controller using yii.

dynamically create table statement in sql

sql sql-server tsql

how to dynamically create a table with same columns as that of previous table. in sql

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.