Code: Select all
mysql> desc contacts;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| f_name | varchar(20) | YES | | NULL | |
| l_name | varchar(20) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| email | varchar(60) | YES | | NULL | |
| hphone | varchar(20) | YES | | NULL | |
| cphone | varchar(20) | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
Code: Select all
mysql> insert into contacts values (0,'s', 's', 32, 'email', 'none', 'nhone');
Query OK, 1 row affected (0.00 sec)
mysql> select * from contacts;
+----+--------+--------+------+-------+--------+--------+
| id | f_name | l_name | age | email | hphone | cphone |
+----+--------+--------+------+-------+--------+--------+
| 1 | s | s | 32 | email | none | nhone |
+----+--------+--------+------+-------+--------+--------+
1 row in set (0.00 sec)
Code: Select all
<?php
include 'config.php';
include 'opendb.php';
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email = $_POST['email'];
$age = $_POST['age'];
$hphone = $_POST['hphone'];
$cphone = $_POST['cphone'];
$query = "insert into contacts (
f_name, l_name, email, age, hphone, cphone) values (
$f_name, $l_name, $email, $age, $hphone, $cphone)";
mysql_query($query) or die(mysql_error());
include 'closedb.php';
echo "<h3>Input Successful!</h3>"
?>
I've tried putting a 0 in the $query VALUES string, and I get tihs error: Column count doesn't match value count at row 1
Can someone help me understand how this should work and why? Thanks in advance!
-Sully