I am new to PHP, I am following an online tutorial in developing an html form to submit data to a php file to insert into a database.
This problem is when I click submit on the form it brings up the php codes in the browser and nothing is inserted into the database.
Here are my codes for the HTML form and the insert.php, both are stored in the htdoc folder.
<html> <head> </head> <body> <form action="insert.php" method="post"> First Name: <input type="text" name="first" size="20"><br> Last Name: <input type="text" name="last" size="20"><br> Phone: <input type="text" name="phone" size="20"><br> Mobile: <input type="text" name="mobile" size="20"><br> Fax: <input type="text" name="fax" size="20"><br> E-mail: <input type="text" name="email" size="20"><br> Web: <input type="text" name="web" size="20"><br> <input type="Submit"> </form> </body> </html>
<?
$username="username";
$password="password";
$database="db";
$table= "aTable";
$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 $table VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);
mysql_close();
?>
any help will be greatful, thanks!
Dave

New Topic/Question
Reply




MultiQuote



|