This is not going online anytime soon. I am just trying to learn PHP/MySQL. This is my first attempt with inserting to a database. I cannot figure out why the data won't insert. This is the HTML form:
<form action="testdbserverside.php" method="post">
Name:<br />
<input type="text" id="ContactName" name="Name" /><br />
E-mail:<br />
<input type="text" id="ContactEmail" name="Email" /><br />
Comment:<br />
<input type="text" id="ContactComment" name="Comment" size="50" />
<br /><br />
<input type="submit" id="submit" name="submit" value="Send">
<input type="reset" id ="reset" value="Reset">
</form>
This is the PHP:
<?php
$ContactName = $_POST["ContactName"];
$ContactEmail = $_POST["ContactEmail"];
$ContactComment = $_POST["ContactComment"];
$sql_connection = mysqli_connect("localhost:8889","root","root","derek_website_tmp");
if (mysqli_connect_errno())
{
echo "failed to connect" . mysqli_connect_error();
}
$sql = "INSERT INTO MyContacts (
ContactName,
ContactEmail,
ContactComment,
ContactDateCreated
)
VALUES (
'$ContactName',
'$ContactEmail',
'$ContactComment',
NOW()
)";
if (!mysqli_query($sql_connection,$sql))
{
die('Error : ' . mysqli_error($sql_connection));
}
mysql_close ($sql_connection);
?>
And this is the database:
mysql> USE derek_website_tmp;
Database changed
mysql> CREATE TABLE MyContacts (
-> ContactID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> ContactName VARCHAR(100),
-> ContactEmail VARCHAR(100),
-> ContactComment VARCHAR(200),
-> ContactDateCreated DATETIME
-> );
Query OK, 0 rows affected (0.19 sec)
Any help would be greatly appreciated. I realize this is not sanitizing anything and is not worthy to go live. I'm just working on getting it to insert for now.
Thank you,