我在html php和javascript中有一个表单设置。我将表单设置为在单击提交按钮时运行process()函数。在这个过程函数中,我给自己发送了一封电子邮件,并将表单中的数据插入到mysql查询中并发送出该查询。
然而,电子邮件代码有效,我收到一封电子邮件,但查询代码没有,因此我的数据库中没有收到新行。我也没有收到mysql_error()输出。
请告诉我我哪里出错了?
function process()
{
mysql_connect("localhost", "username", "password");
mysql_select_db("db");
$device = mysql_real_escape_string($_POST['Device_Type']);
$name = mysql_real_escape_string($_POST['Name']);
$job = mysql_real_escape_string($_POST['DD']);
$username = mysql_real_escape_string($_POST['Username']);
$email = mysql_real_escape_string($_POST['Email']);
$website = mysql_real_escape_string($_POST['Website']);
$UDID = mysql_real_escape_string($_POST['UDID']);
mysql_query("INSERT INTO Beta_Testers (`Name`, `Username`, `Email Address`, `Website`, `Job`, `Device_Type`, `UDID`) VALUES ('$name','$username','$email','$website','$job','$device','$UDID'))") or die(mysql_error());
$msg = "Form Contents: \n\n";
foreach($this->fields as $key => $field)
$msg .= "$key : $field \n";
$to = 'beta@socialpic.org';
$subject = 'Beta Form Submission';
$from = 'Beta Sign up';
mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
}
答案 0 :(得分:0)
由于mysql_query()是您正在使用它的上下文中的布尔函数,因此您可以执行以下操作:
function process()
{
mysql_connect("localhost", "username", "password");
mysql_select_db("db");
$device = mysql_real_escape_string($_POST['Device_Type']);
$name = mysql_real_escape_string($_POST['Name']);
$job = mysql_real_escape_string($_POST['DD']);
$username = mysql_real_escape_string($_POST['Username']);
$email = mysql_real_escape_string($_POST['Email']);
$website = mysql_real_escape_string($_POST['Website']);
$UDID = mysql_real_escape_string($_POST['UDID']);
$query = "INSERT INTO Beta_Testers (`Name`, `Username`, `Email Address`, `Website`, `Job`, `Device_Type`, `UDID`) VALUES ('$name','$username','$email','$website','$job','$device','$UDID'))";
if (mysql_query($query)) {
$msg = "Form Contents: \n\n";
foreach($this->fields as $key => $field)
$msg .= "$key : $field \n";
$to = 'beta@socialpic.org';
$subject = 'Beta Form Submission';
$from = 'Beta Sign up';
mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
} else {
echo $query;
}
}
但是查看您的代码,您的电子邮件地址列是“电子邮件地址”还是“电子邮件地址”?