Ok i'm new to php. I'm just trying to write a simple form which writes values to db table. Anyway:
the form:
<html>
<body>
<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="Submit">
</form>
</body>
</html>
insert.php
<?
$username="root";
$password="numberone";
$database="php";
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES (' ', '$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
echo $query;
mysql_close();
?>
You have successfully registered!
<? echo $first ?>
<br/><? echo $last ?>
<br/><? echo $phone ?>
<br/><? echo $mobile ?>
<br/><? echo $fax ?>
<br/><? echo $email ?>
<br/><? echo $web ?>
what happens is nothing is written to the db unless i change INSERT INTO contacts VALUES (' ',
and specify an actual number, which is strange seeing as though i have id as AUTO_INCREMENT.
the above produces:
INSERT INTO contacts VALUES (' ', 'John','Doe','29332932','923293923','93282938','johndoe@somewhere.com','kdsjksd') You have successfully registered! John
Doe
29332932
923293923
93282938
johndoe@somewhere.com
kdsjksd
but nothing is written.
DB schema as follows:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for contacts
-- ----------------------------
CREATE TABLE `contacts` (
`id` int(6) NOT NULL auto_increment,
`first` varchar(15) NOT NULL,
`last` varchar(15) NOT NULL,
`phone` varchar(20) NOT NULL,
`mobile` varchar(20) NOT NULL,
`fax` varchar(20) NOT NULL,
`email` varchar(30) NOT NULL,
`web` varchar(30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `id_2` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;