Hi Guys,
Been talking to a friend about my code I have been working on.I could not figure out how for the life of me to check whether an email or code in my database is already in use. So just to cool down for a bit i put conditions in my code to check whether all fields has been filled out, or if they haven't. When the two integer columns have not been filled out (Telephone, Code) I get this error;
Error updating database because: Incorrect integer value: '' for column 'Code' at row 1
My friend says I have tried to jump to stage to 5 and not doing the other stages correctly. Can you have a look at the code and explain to me what i am doing wrong and where to improve?? Thanks guys
<?php
if($_POST){
mysql_connect ("localhost", "root", "root") or die ('Error: ' . mysql_error());
mysql_select_db ("wowcher") or die ('Error: ' . mysql_error());
$First_name = $_POST['First_Name'];
$Surname = $_POST['Last_Name'];
$Email = $_POST['Email'];
$Code = $_POST['Code'];
$Telephone = $_POST['Phone'];
$errorMessage = "";
$id = isset($Telephone) ? trim($Telephone) : " ";
$query="INSERT INTO wowcher_code(First_name, Last_Name, Email, Code, Telephone)VALUES ('".$First_name."', '".$Surname."', '".$Email."', '".$Code."', '".$Telephone."')";
mysql_query($query) or die ('Error updating database because: '.mysql_error());
if(empty($_POST['First_Name']))
{
$errorMessage .= "<li>You forgot to enter your Name</li>";
}
if(empty($_POST['Last_Name']))
{
$errorMessage .= "<li>You forgot to enter your Surname</li>";
}
if(empty($_POST['Email']))
{
$errorMessage .= "<li>You forgot to enter your Email</li>";
}
if(empty($_POST['Code']))
{
$errorMessage .= "<li>You forgot to enter your Wowcher code you silly person!</li>";
}
if(empty($_POST['Phone']))
{
$errorMessage .= "<li>You forgot to enter your Phone Number</li>";
}
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
}
else{
if(!empty($_POST['First_Name']))
{
}
if(!empty($_POST['Last_Name']))
{
}
if(!empty($_POST['Email']) or )
{
}
if(!empty($_POST['Code']))
{
}
if(!empty($_POST['Phone']))
{
}
echo("<p>Congrations details successfully added!</p>\n");
}
mysql_close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Wowcher Code Submission</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div class="container">
<form method ="post" action="index.php">
<label>First name:</label><br>
<input type="text" name="First_Name"><br>
<label>Last name:</label><br>
<input type="text" name="Last_Name"><br>
<label>Email:</label><br>
<input type="text" name="Email"><br>
<label>Wowcher Code:</label><br>
<input type="text" name="Code"><br>
<label>Telephone Number:</label><br>
<input type="text" name="Phone"><br>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>