Reputation: 15
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!
Upvotes: 0
Views: 2748
Reputation: 180947
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);
Upvotes: 2
Reputation: 34054
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.
Upvotes: 2