我正在尝试编写一个 php 脚本,它将接受 POST 变量并将它们保存到数据库中,然后发送一封包含这些变量的电子邮件。
我已经使用我之前单独使用过的方法将以下内容放在一起,没有问题。当我在页面上收到以下警告时,我在这里的某个地方犯了一个错误:Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ws')' at line 16
我不明白这个警告,因为第 16 行或附近没有“ws”)。
我没有得到什么?
我取出了所有保存到数据库的代码,电子邮件工作正常,但我仍然看不出数据库代码有什么问题。
<?php
$email = $_POST['email'] ;
$number = $_POST['number'] ;
$ext = $_POST['ext'] ;
$startDay = $_POST['startDay'] ;
$endDay = $_POST['endDay'] ;
$startTime = $_POST['startTime'] ;
$endTime = $_POST['endTime'] ;
$startDay2 = $_POST['startDay2'] ;
$endDay2 = $_POST['endDay2'] ;
$startTime2 = $_POST['startTime2'] ;
$endTime2 = $_POST['endTime2'] ;
$sine = $_POST['sine'] ;
$webmaster_email = "support@website.com";
$hostname = "Sines.db.42.mywebresource.com";
$username = "Sines";
$dbname = "Sines";
$password = "Password!";
$usertable = "contact";
$con = mysql_connect($hostname, $username, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $con);
$sql="INSERT INTO contact (
`email` ,
`number` ,
`ext` ,
`startDay` ,
`endDay` ,
`startTime` ,
`endTime` ,
`startDay2` ,
`endDay2` ,
`startTime2` ,
`endTime2` ,
`sine`
)
VALUES
('$_POST[email]','$_POST[number]','$_POST[ext]','$_POST[startDay]','$_POST[endDay]','$_POST[startTime]','$_POST[endTime]','$_POST[startDay2]','$_POST[endDay2]','$_POST[startTime2]','$_POST[endTime2]'),'$_POST[sine]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "User", ' ' , mysql_insert_id() , ' ' ,"added";
$_SESSION["PRid"] = mysql_insert_id();
mysql_close($con);
/*Below is for sending the email.*/
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
if ( isInjected($email) ) {
}
else {
$contents = <<<EOM
Email: $email
Number: $number
Ext: $ext
StartDay: $startDay
EndDay: $endDay
StartTime: $startTime
EndTime: $endTime
StartDay2: $startDay2
EndDay2: $endDay2
StartTime2: $startTime2
EndTime2: $endTime2
Sine: $sine
EOM;
mail( "$webmaster_email", "Contact", $contents);
}
?>
我的数据库: