I am trying to get my php validate that the user has put in the info that is needed.
I want to make sure that the person has put in there name and email. When I put just:
if(empty($name){
blah blah
}
it gives the error but it still process the email. When I put:
if(empty($name){
blah blah
}else{
blah blah
}
I get an error saying: Parse error: syntax error, unexpected '}' in /home/dreamcpu/public_html/insert.php on line 34.
Here is my php:
<?php
$con = mysql_connect("localhost","blah","blah");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$today = date("F j, Y, g:i a");
mysql_select_db("dreamcpu_contact_info", $con);
$sql="INSERT INTO contact_us (name, email,phone_number,job_request,DateRequested)
VALUES
('$_POST[name]','$_POST[email]','$_POST[phone_number]','$_POST[job_requested]','$today')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error(). "Actual query: " . $sql);
}
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone_number'];
$job = $_POST['job_requested'];
if (empty($name)){
echo "The name field was blank. Please go back and fill in the required fields";
}
else
{
$to = "programmers@dreamcpu.com";
$subject = "A job have been requested";
$message = "On " . $today . " a job has been requested from " . $name . " please email them at " . $email . " or call them at " . $phone;
$headers = "From:" . $email;
mail($to, $subject, $message,$headers);
echo "<h3 style='display:block;'>Thank you for contacting DreamCPU. We have received your request $_POST[name]. We will review it and contact you as soon as possible.</h3>";
mysql_close($con);
}
?>
You forgot a semicolon:
The variable inside your string should also not be relying on constants:
You also forgot a closing bracket on this line: