我在 PHP 中的 MySQL 查询需要一些帮助
在我再说说我使用mysql_*
函数之前,我知道它们已经被贬值了,但是只有 PHP v5.5 并且我在我的服务器上安装了 PHP 5.3 并且其他mysql_*
函数都在使用它。
我正在尝试将表单中的值插入表单提交的表格中,代码位于正确的位置,因为 PHP 发送电子邮件并回显“发送的邮件”。
这是我的查询:
mysql_query("INSERT INTO customers (
name,email,telephone
) VALUES (
".$_POST['name'].",
".$_POST['email'].",
".$_POST['telephone'].",
)");
这是它所在的文档:
<?php
// Database connect
$db_host = 'localhost';
$db_user = 'redjaxco';
$db_pass = 'CORRECT PASSWORD';
$db_database = 'redjaxco_website';
$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");
$owner_email = "contact@red-jax.com";
$headers = 'From:' . $_POST["email"];
$subject = 'Online Form - '. $_POST["topic"]. " : " . $_POST["name"];
$messageBody = "";
if($_POST['topic']!='nope'){
$messageBody .= '<p>Subject: ' . $_POST["topic"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['name']!='nope'){
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['phone']!='nope'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
if(!mail($owner_email, $subject, $messageBody, $headers))
{
throw new Exception('mail failed');
}
else
{
mysql_query("INSERT INTO customers (
name,email,telephone
) VALUES (
".$_POST['name'].",
".$_POST['email'].",
".$_POST['telephone'].",
)");
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>