The number of columns does not match the number of values ​​in row 1 php mysql

When you click the "AD RECORD" button, the following error appears:

INSERT failed: INSERT INTO user_master VALUES ('cha', 'rstein', 'bar', 'foo') The number of columns does not match the number of values ​​in row 1

from the following code:

if (isset($_POST['delete']) && isset($_POST['first'])) { $first = get_post('first'); $query = "DELETE FROM user_master WHERE first='$first'"; if(!mysql_query($query, $db_server)) echo "DELETE failed: $query<br />" . mysql_error() . "<br /><br />"; } if (isset($_POST['first']) && isset($_POST['last']) && isset($_POST['user_name']) && isset($_POST['email'])) { $first = get_post('first'); $last = get_post('last'); $email = get_post('email'); $user_name = get_post('user_name'); $query = "INSERT INTO user_master VALUES" . "('$first' , '$last' , '$user_name' , '$email')"; if(!mysql_query($query, $db_server)) echo "INSERT failed: $query <br />" . mysql_error() . "<br /><br />"; } echo <<<END <form action = "willingLog.html" method="post"><pre> First <input type="text" name="first" /> Last <input type="text" name="last" /> Email <input type="text" name="email" /> Username <input type="text" name="user_name" /> <input type="submit" value="AD RECORD" /> </pre></form> END; 
+4
source share
4 answers

There are more columns in the database table, after which you insert them to get an error. (You probably do not represent your userID field, which is probably your primary key). You need to indicate in which fields the data is in your request:

  $query = "INSERT INTO user_master (first_name, last_name, user_name, email) VALUES" . "('$first' , '$last' , '$user_name' , '$email')"; 
+12
source

If your user_master table has any primary key, such as id or user_id , you can do two things:

  • You can add the auto_increment attribute to the id field
  • Add the primary value for "id".
0
source

I had the same problem ... the way I solved it, making sure it didn't put a comma in my integer values .

therefore, if you enter salary in the html form, do not put commas in the salary indicator. (I follow the examples in the Tutorials section. I thought the salary field should contain a comma, but this caused this error.)

0
source

Make sure your sql query has no spaces next to the parenthesis. The following is the error you mentioned:

 $sql = "INSERT INTO table_name ( email, username ) VALUES ($userEmail,$username)" 
0
source

All Articles