By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,889 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,889 IT Pros & Developers. It's quick & easy.

Column count doesn't match value count at row 1

P: 17
this code is producing the message BUT it is entering the data. What should i do?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (!$_POST) {
  3.     //haven't seen the form, so show it
  4.     $display_block = "
  5.     <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
  6.     <p><strong>First/Last Names:</strong><br/>
  7.     <input type=\"text\" name=\"f_name\" size=\"30\" maxlength=\"75\">
  8.     <input type=\"text\" name=\"l_name\" size=\"30\" maxlength=\"75\"></p>
  9.  
  10.     <p><strong>Address:</strong><br/>
  11.     <input type=\"text\" name=\"address\" size=\"30\"></p>
  12.  
  13.     <p><strong>City/State/Zip:</strong><br/>
  14.     <input type=\"text\" name=\"city\" size=\"30\" maxlength=\"50\">
  15.     <input type=\"text\" name=\"state\" size=\"5\" maxlength=\"2\">
  16.     <input type=\"text\" name=\"zipcode\" size=\"10\" maxlength=\"10\"></p>
  17.  
  18.     <p><strong>Address Type:</strong><br/>
  19.     <input type=\"radio\" name=\"add_type\" value=\"home\" checked> home
  20.     <input type=\"radio\" name=\"add_type\" value=\"work\"> work
  21.     <input type=\"radio\" name=\"add_type\" value=\"other\"> other</p>
  22.  
  23.     <p><strong>Telephone Number:</strong><br/>
  24.     <input type=\"text\" name=\"tel_number\" size=\"30\" maxlength=\"25\">
  25.     <input type=\"radio\" name=\"tel_type\" value=\"home\" checked> home
  26.     <input type=\"radio\" name=\"tel_type\" value=\"work\"> work
  27.     <input type=\"radio\" name=\"tel_type\" value=\"other\"> other</p>
  28.  
  29.     <p><strong>Fax Number:</strong><br/>
  30.     <input type=\"text\" name=\"fax_number\" size=\"30\" maxlength=\"25\">
  31.     <input type=\"radio\" name=\"fax_type\" value=\"home\" checked> home
  32.     <input type=\"radio\" name=\"fax_type\" value=\"work\"> work
  33.     <input type=\"radio\" name=\"fax_type\" value=\"other\"> other</p>
  34.  
  35.     <p><strong>Email Address:</strong><br/>
  36.     <input type=\"text\" name=\"email\" size=\"30\" maxlength=\"150\">
  37.     <input type=\"radio\" name=\"email_type\" value=\"home\" checked> home
  38.     <input type=\"radio\" name=\"email_type\" value=\"work\"> work
  39.     <input type=\"radio\" name=\"email_type\" value=\"other\"> other</p>
  40.  
  41.     <p><strong>Personal Note:</strong><br/>
  42.     <textarea name=\"note\" cols=\"35\" rows=\"3\" wrap=\"virtual\"></textarea></p>
  43.  
  44.     <p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>
  45.     </form>";
  46.  
  47. } else if ($_POST) {
  48.     //time to add to tables, so check for required fields
  49.     if (($_POST["f_name"] == "") || ($_POST["l_name"] == "")) {
  50.         header("Location: addentry.php");
  51.         exit;
  52.     }
  53.  
  54.     //connect to database
  55.     $mysqli = mysqli_connect("localhost", "web86-geothermal", "pw002f1945", "web86-geothermal");
  56.  
  57.     //add to master_name table
  58.     $add_master_sql = "INSERT INTO tbl_master_name (master_id, date_added, date_modified, f_name, l_name)
  59.                        VALUES ('', now(), now(), '".$_POST["f_name"]."', '".$_POST["l_name"]."')";
  60.     $add_master_res = mysqli_query($mysqli, $add_master_sql) or die(mysqli_error($mysqli));
  61.  
  62.     //get master_id for use with other tables
  63.     $master_id = mysqli_insert_id($mysqli);
  64.  
  65.     if (($_POST["address"]) || ($_POST["city"]) || ($_POST["state"]) || ($_POST["zipcode"])) {
  66.         //something relevant, so add to address table
  67.         $add_address_sql = "INSERT INTO tbl_address (master_id, date_added, date_modified,
  68.                             address1, address2, city, state, zipcode, type)  VALUES ('".$master_id."',
  69.                             now(), now(), '".$_POST["address"]."', '".$_POST["city"]."',
  70.                             '".$_POST["state"]."' , '".$_POST["zipcode"]."' , '".$_POST["add_type"]."')";
  71.         $add_address_res = mysqli_query($mysqli, $add_address_sql) or die(mysqli_error($mysqli));
  72.     }
  73.  
  74.     if ($_POST["tel_number"]) {
  75.         //something relevant, so add to telephone table
  76.         $add_tel_sql = "INSERT INTO tbl_telephone (master_id, date_added, date_modified,
  77.                         tel_number, type)  VALUES ('".$master_id."', now(), now(),
  78.                         '".$_POST["tel_number"]."', '".$_POST["tel_type"]."')";
  79.         $add_tel_res = mysqli_query($mysqli, $add_tel_sql) or die(mysqli_error($mysqli));
  80.     }
  81.  
  82.     if ($_POST["fax_number"]) {
  83.         //something relevant, so add to fax table
  84.         $add_fax_sql = "INSERT INTO tbl_fax (master_id, date_added, date_modified,
  85.                         fax_number, type)  VALUES ('".$master_id."', now(), now(),
  86.                         '".$_POST["fax_number"]."', '".$_POST["fax_type"]."')";
  87.         $add_fax_res = mysqli_query($mysqli, $add_fax_sql) or die(mysqli_error($mysqli));
  88.     }
  89.  
  90.     if ($_POST["email"]) {
  91.         //something relevant, so add to email table
  92.         $add_email_sql = "INSERT INTO tbl_email (master_id, date_added, date_modified,
  93.                           email, type)  VALUES ('".$master_id."', now(), now(),
  94.                           '".$_POST["email"]."', '".$_POST["email_type"]."')";
  95.         $add_email_res = mysqli_query($mysqli, $add_email_sql) or die(mysqli_error($mysqli));
  96.     }
  97.  
  98.     if ($_POST["note"]) {
  99.         //something relevant, so add to notes table
  100.         $add_notes_sql = "INSERT INTO tbl_personal_notes (master_id, date_added, date_modified,
  101.                           note)  VALUES ('".$master_id."', now(), now(), '".$_POST["note"]."')";
  102.         $add_notes_res = mysqli_query($mysqli, $add_notes_sql) or die(mysqli_error($mysqli));
  103.     }
  104.     mysqli_close($mysqli);
  105.     $display_block = "<p>Your entry has been added.  Would you like to <a href=\"addentry.php\">add another</a>?</p>";
  106. }
  107. ?>
  108. <html>
  109. <head>
  110. <title>Add an Entry</title>
  111. </head>
  112. <body>
  113. <h1>Add an Entry</h1>
  114. <?php echo $display_block; ?>
  115. </body>
  116. </html> 
Feb 11 '08 #1
Share this Question
Share on Google+
3 Replies


harshmaul
Expert 100+
P: 490
Hi,
when your inserting address it looks like you missed out a value...

remember the insert syntax is....

Expand|Select|Wrap|Line Numbers
  1. insert into tblName (column1, column2) values ("column1","column2")
you've got something like this...

Expand|Select|Wrap|Line Numbers
  1. insert into tblName (column1, column2) values ("column1")
Where you've missed one of the columns.

let me know how you get on.
Feb 11 '08 #2

P: 17
aha, found it.

So the message actually means that your mysql column count doesnt match the number of values it has to insert into db
Feb 11 '08 #3

harshmaul
Expert 100+
P: 490
yea, it could be insert, or update, i think even select if you make up the name for a column ;)

glad you solved it :)
Feb 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.