No records show up in my MyPHP Database when I run these scripts.
I am running: APACHE 2.4.7 MYSQL 5.6.15 PHP 5.5.8
First the HTML Code...
<html>
<center>
<font face="Helvetica">
<u><b>Matthew Gieger's Guestbook</b></u>
<form action="link.php" method="post"/>
<p>Name: </p>
<input type="text" name="Name" required/>
<p>Email: </p>
<input type="email" name="Email" required />
<p>Message: </p>
<p><textarea rows="4" cols="50" name="Message"> </textarea></p>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</center>
</html>
And the PHP Script. This is where I think the problem is...
<?php
$username='root';
$password='';
$database='guestbook';
$name= $_POST['Name'];
$email= $_POST['Email'];
$message= $_POST['Message'];
new mysqli('localhost',$username,$password,$database) or die("could not connect to localhost");
echo"connected";
mysqli:"insert into contacts (Name,Email,Message,Timestamp) values ($name,$email,$message,date())";
?>
I get no error when I run the code. I just get the expected "connected"
You don't have a mysqli
object defined anywhere. And you're not using mysqli_query()
anywhere.
Try something like this:
$mysqli = new mysqli('localhost', $username, $password, $database);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$mysqli->query("INSERT INTO `contacts`(`Name`, `Email`, `Message`, `Timestamp`) VALUES ('". $name ."', '". $email ."', '". $message ."', '". $timestamp ."')");