Its a really simple script, or at least it should be. I am kinda not sure around pHp so Im not sure where I am going wrong.
This page is called from a submit button on a form, all it is supposed to do is capture the name, email address and date of submission and add it to my database.
I can connect to the database without issue but cannot add to the database.
For some reason, everytime I load this page I also get a blank screen. pHp / SQL doesnt look like it has friendly bug reporting.
Here is the code with obvious info take outs.
<html>
<head>
</head>
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "123";
$db_name = "emailtest";
$conn = @mysql_connect($db_host,$db_username,$db_pass,$db_name);
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
} else {
echo "Good connection ";
}
if(!empty($_REQUEST['name']))
{
$name = $_REQUEST['name'];
echo "hello, $name ";
if(!empty($_REQUEST['email']))
{
$email = $_REQUEST['email'];
}
else
{
$email = NULL;
}
if($email)
{
if ($conn->query($sql) === TRUE)
{
$dateTime = date("Y/m/d");
$sql = "INSERT INTO Newsletter_signup (name, email, sign_up_date) VALUES('$name','$email','$dateTime')";
echo "Record updated successfully <br/>";
echo "The email address, $email , has been added to the newsletter.";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
else
{
echo 'Please go back and insert an email address.';
}
?>
<body id="body">
// body style stuff
</body>
</html>