- Jun 13, 2000
- 26,391
- 1,780
- 126
I posted the question a while back about how to create a contact form and output the data to a SQL database. I got some good responses. I've created a table and an insert.php file to insert data into the table....my problem is that it doesn't seem to be working. Can anyone take a look and see if I made a mistake somewhere?
I setup the DB to have an id as the primary key and it's an autonumber. I don't know if I need to reference that somewhere... The fields in the table are fname, lname, etc...and I created variables for these, just to follow the tutorial's example.
The error messages built-in let me know that I'm connecting to the DB successfully and selecting it. Thanks for any insight.
$username="dbuser";
$password="password";
$database="Customerdb";
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$company=$_POST['company'];
$addr1=$_POST['addr1'];
$addr2=$_POST['addr2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$natureID=$_POST['natureID'];
$comments=$_POST['comments'];
$link = mysql_connect(localhost,$username,$password);
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
die ('Can\'t use selected database : ' . mysql_error());
}
$query = "INSERT INTO contact (id,fname,lname,company,addr1,addr2,city,state,zip,phone,mobile,fax,email,natur
ID,comments) VALUES ('','$fname','$lname','$company','$addr1',$addr2','$city','$state','$zip','$phone','$mobile','$fax','$email','$natureID','$comments')";
mysql_query($query);
mysql_close();
I setup the DB to have an id as the primary key and it's an autonumber. I don't know if I need to reference that somewhere... The fields in the table are fname, lname, etc...and I created variables for these, just to follow the tutorial's example.
The error messages built-in let me know that I'm connecting to the DB successfully and selecting it. Thanks for any insight.
$username="dbuser";
$password="password";
$database="Customerdb";
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$company=$_POST['company'];
$addr1=$_POST['addr1'];
$addr2=$_POST['addr2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$natureID=$_POST['natureID'];
$comments=$_POST['comments'];
$link = mysql_connect(localhost,$username,$password);
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
die ('Can\'t use selected database : ' . mysql_error());
}
$query = "INSERT INTO contact (id,fname,lname,company,addr1,addr2,city,state,zip,phone,mobile,fax,email,natur
ID,comments) VALUES ('','$fname','$lname','$company','$addr1',$addr2','$city','$state','$zip','$phone','$mobile','$fax','$email','$natureID','$comments')";
mysql_query($query);
mysql_close();