Help: Column count doesn't match value count at row 1

I am trying to create a signup page, at first when i was having 4 columns in database table, i din hav a prob… but now when i added extra columns to suit my requirements… its not working :frowning: :frowning: :frowning: :frowning: :frowning:
[hr]This is my “signup.php” code[hr]


<?php include_once("db.php") ?> <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $rollno = $_POST['roll']; $username = $_POST['name']; $password = $_POST['pass']; $date = $_POST['date']; $phone = $_POST['phone']; $email = $_POST['email']; $sql = "INSERT into login values('".$firstname."','".$lastname."',".$rollno.",'".$username."','".$password."','".$date."',".$phone.",'".$email."')"; $qury = mysql_query($sql); if(!$qury) echo "failed".mysql_error(); else{ echo "successful";} ?>


[hr]This is my “Signupform.php” code[hr]




[hr]This is my Database table[hr]

| ID | firstname | lastname | rollno | username | password | date | phone | email | mark |

| | | | | | | | | | |
| | | | | | | | | | |
| | | | | | | | | | |
| | | | | | | | | | |
| | | | | | | | | | |

[hr]This is my error[hr]

Column count doesn’t match value count at row 1” ---------- Please help me fix this problem :frowning: :frowning: :frowning: :frowning: is that necessary to post al the columns in the database? cuz “mark” column i am using here is to store user’s mark from “quiz.php” page, which is a different page. Will it create any problem???

Thank you in advance :frowning: please help me solve this problem, i am just a beginner…

[hr]This is database table in exact figures…[hr]

CREATE TABLE IF NOT EXISTS `login` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(25) NOT NULL, `lastname` varchar(25) NOT NULL, `rollno` int(11) NOT NULL, `username` varchar(25) NOT NULL, `password` varchar(25) NOT NULL, `date` varchar(10) NOT NULL, `phone` bigint(15) NOT NULL, `email` varchar(35) NOT NULL, `mark` int(11) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

It’s your SQL statement that’s the problem, the syntax is like this:

[php]$sql = “INSERT into login (firstname, lastname, rollno, username, password, date, phone, email)

The syntax is fine, if that is the correct number of columns. It’s more likely that $phone isn’t an integer


should be


OK, but I thought that

$sql = “INSERT into login values(’”.$firstname."’,’".$lastname."’,".$rollno.",’".$username."’,’".$password."’,’".$date."’,".$phone.",’".$email."’)";

would only work if you’re putting a value in every field in the table, which we’re not here.

You are right I didn’t notice the ID field missing. It is much better to specify column names anyhow :wink:


I’ve set ID in auto increment mode… do i need to specify it for sure??


Hey! you are correct! the mistake is on me… i just followed a tutorial in internet… i am just a beginner! thanks for solving my issue! many thanks to you… :slight_smile: :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service