PHP邮件空白变量

时间:2011-12-20 20:52:50

标签: php

我试图让我的php验证用户已经输入了所需的信息。

我想确保此人已在其中输入姓名和电子邮件。当我放下时:

if(empty($name){
  blah blah
}

它给出了错误,但它仍处理电子邮件。当我把:

if(empty($name){
  blah blah
}else{
  blah blah
}

我收到错误消息:Parse error: syntax error, unexpected '}' in /home/dreamcpu/public_html/insert.php on line 34

这是我的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);
}
?>

2 个答案:

答案 0 :(得分:5)

你忘记了分号:

mysql_close($con);
-----------------^

字符串中的变量也不应该依赖于常量:

echo " ... request $_POST['name']. We will ...";
--------------------------^----^

你也忘记了这一行的结束括号:

if(empty($name)){
---------------^
  blah blah
}

答案 1 :(得分:3)

使用分号。

mysql_close($con);