Hey all, cant get this very very simple query to work but I have been going 26 hours and my thoughts are numb. Please assist? I have error reporting on and request mysql errors but I'm getting nothing.
Contents of config.php
$db_host = 'localhost'; //IP of database server (most likely 'localhost')
$db_username = 'root'; //Username to access database
$db_password = ''; //Password used to access database
$con = mysql_connect($db_host, $db_username, $db_password);
if (!$con)
{
die('Could not connect to the database. Email are not currently being stored.');
}else{
$select_db = mysql_select_db('email', $con);
if (!$select_db) {
die ('Can\'t select database : ' . mysql_error());
}
}
The form:
<form method="post">
<div id="subscribe">
<input type="text" placeholder="Enter your email address for updates!" id="email" name="email">
<input type="submit" value="Subscribe">
<div class="clear"></div>
</div>
</form>
The script to insert subscribers email:
require('config.php');
if(isset($_POST['submit'])){
@$email = $_POST['email'];
@$date = date('d/m/Y H:i');
if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $email) || empty($email)) {
echo 'The email address entered is invalid.';
} else {
$query = "INSERT INTO subscribers (id, email, date) VALUES ('', '$email', '$date')";
mysql_query($query) or die('Query "' . $query . '" failed: ' . mysql_error());
}
}
Thanks in advance!