This is my code.
I want the form included to send data to a table called 'contacts' in a MySQL database I have created.
There are four fields in the table; Title, Name, Email, Enquiry.
This is code that I have copied and edited to suit my website. I am new to .PHP!
<?php
if(isset($_POST['add'])) {
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc() ) {
$p_title = addslashes ($_POST['p_title']);
$p_name = addslashes ($_POST['p_name']);
$p_email = addslashes ($_POST['p_email']);
}else {
$p_name = $_POST['p_name'];
$p_email = $_POST['p_email'];
}
$p_enquiry = $_POST['p_enquiry'];
$sql = "INSERT INTO contacts ". "(p_name,p_email, p_enquiry, p_title
join_date) ". "VALUES('$p_name','$p_email',$p_enquiry,$p_title NOW())";
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}else {
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border = "0" cellspacing = "1"
cellpadding = "2">
<tr>
<td width = "100"><p>Title:</p></td>
<td><input name = "p_title" type = "text"
id = "p_title"></td>
</tr>
<tr>
<td width = "100"><p>Name:</p></td>
<td><input name = "p_name" type = "text"
id = "p_name"></td>
</tr>
<tr>
<td width = "100"><p>Email:</p></td>
<td><input name = "p_email" type = "text"
id = "p_email"></td>
</tr>
<tr>
<td width = "100"><p>Enquiry:</p></td>
<td><input name = "p_enquiry" type = "text"
id = "p_enquiry"></td>
</tr>
<tr>
<td width = "100"> </td>
<td> </td>
</tr>
<tr>
<td width = "100"> </td>
<td>
<input name = "add" type = "submit" id = "add"
value = "Add Employee">
</td>
</tr>
</table>
</form>
<?php
}
?>