【发布时间】:2017-01-11 08:00:52
【问题描述】:
这是我有一个 java 字符串纪元日期,我想比较并将数据添加到 SQL 它给出一个解析错误不知道为什么有任何解决方案..
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting values
$number = $_POST['number'];
$type = $_POST['type'];
$date = $_POST['date'];
$content = $_POST['content'];
$start = strtotime("now");
$end = strtotime("-7 days");
while($start->format('U') > $date->format('U') > $end->format('U')){
$sql = "INSERT INTO message_detail (number,type,date,content) VALUES ('$number','$type','$date','$content')";
//Importing our db connection script
require_once('connect.php');
//Executing query to database
if(mysqli_query($con,$sql)){
echo 'Entry Added Successfully';
}else{
echo 'Could Not Add Entry';
}
}
//Closing the database
mysqli_close($con);
}
?>
【问题讨论】:
-
在我看来,您的代码存在一些问题。首先,您将 db 连接脚本包含在一个循环中,其次您将变量直接嵌入到 sql 中,从而使其容易受到 sql 注入攻击。