I don't code often but I've done this a few times and can't figure out why it isn't working. Am I missing something in the code? After the users clicks submit everything looks fine! No errors and it displays the thank you with variables correct. For some reason it doesn't write the MySQL table though. Any ideas?
<?php
//----Connecting to the Database---------------------------------------------------------------------------------------------
$dbh=mysql_connect ("localhost", "esander_eDBuser", "eDBuPW")
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("esander_emailsDB");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
if(isset($_POST['emailForm'])) {
//set Input Variables
$email = $_POST['email'];
$name = $_POST['name'];
$sql = "INSERT INTO `esander_emailsDB`.`emails` (`name`,`email`) VALUES ('$name','$email');";
$result = mysql_query($sql);
echo $result."<br />";
echo "Thank You ".$name.". An email has been sent to ".$email." with the daily code.";
}
else {
?>
<form id="emailForm" name="emailForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Please enter your name and email address below for the daily code<br />
<input name="name" type="test" value="Your Name" size="26" />
<span id="sprytextfield1">
<label>
<input name="email" type="text" id="email" value="Email Address" size="40" />
</label>
<br /><input name="emailForm" type="Submit" />
<span class="textfieldRequiredMsg">A value is required.</span></span>
</form>
<?php
}
?>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "email");
//-->
</script>
</body>
</html>
Thanks in advance!