解析错误:C:\ xampp \ htdocs \ cc_real \ 3HLR14CMORCGZ0IY8AE7H4JL409RV9 \ insert中的语法错误,意外“”,期望标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)。 php上 第15行。
显示此错误,以下是我尝试用于将数据插入数据库的代码。
.two {
transition: all 2s ease-in-out 0.5s;
-webkit-transition: all 2s ease-in-out 0.5s;
}
#scale {
height: 150px;
width: 100px;
text-align: center;
margin: 0 auto;
}
#scale {
border: 1px blue solid;
}
.grow:hover {
transform: scale(2.0);
/*-ms-transform: scale(2.0);*/
-webkit-transform: scale(2.0);
}
答案 0 :(得分:1)
这段代码有几个问题。
;
$con
功能的mysqli_
参数mysql_
和mysqli_
$_post
代替$_POST
(大写字母)查看代码周围的注释,了解更改内容。
<?php
echo "Invoked!!!";
$con = mysqli_connect('localhost', 'root', '');
/*
You can also do this, and drop mysqli_select_db() later in the code
$con = mysqli_connect('localhost', 'root', '', 'job1');
*/
if (!$con) {
// Cannot mix mysql with mysqli (changed out mysql_error())
// Also, mysqli has "mysqli_connect_error()" for connecting errors
die('could not connect: '.mysqli_connect_error());
}
// This function require the $con parameter
mysqli_select_db($con, 'job1');
// Quotes being messed up - this is your current error
// Concatenate the POST values instead, like this
// Also using $_post instead of $_POST
$sql = "INSERT INTO `cc_job2` (cc_Answer_filename, cc_time, cc_workerID) VALUES ('".$_POST["Answer_filename"]."', '".$_POST["track_data"]."', '".$_POST["workerID"]."')";
// Missing $con as the first parameter and ; at the end
$result = mysqli_query($con, $sql);
if ($result) {
// Missing ; at the end
echo "<br> Input data is succeed";
} else{
echo "<br> Input data is failed";
// You should add echo mysqli_error($con); here to troubleshoot queries
}
mysqli_close($con);
?>
请注意,如果任何POST值包含单引号'
,查询将失败,因此您应该转义它们,或者更好的是,使用预准备语句(请参阅下面的段落和链接&#34;如何在PHP中阻止SQL注入?&#34;在底部。
此代码也容易受到SQL注入攻击,您应该使用带有占位符的预准备语句来防范这种情况。
请参阅以下链接
答案 1 :(得分:0)
只需添加;
行echo ("<br> Input data is succeed")
和$result = mysqli_query($sql)
的结尾。
尝试这样的事情。
<?php
echo "Invoked!!!";
$con = mysqli_connect('localhost', 'root', '');
if (!$con)
{
die('could not connect:'.mysql_error());
}
mysqli_select_db('job1');
Error: $sql = "INSERT INTO cc_job2(cc_Answer_filename,cc_time,cc_workerID) VALUES ('".$_post['Answer_filename']."','".$_post['track_data']."','".$_post['workerID']."')";
$result = mysqli_query($sql);
if ($result){
echo ("<br> Input data is succeed");
}else{
echo("<br> Input data is failed");
}
mysqli_close($con);
?>
答案 2 :(得分:0)
$sql = "INSERT INTO `cc_job2`(cc_Answer_filename,cc_time,cc_workerID) VALUES ('".$_post['Answer_filename']."','".$_post['track_data']."','".$_post['workerID']."')";
答案 3 :(得分:0)
在mysql查询中结束:
<?php
echo "Invoked!!!";
$con = mysqli_connect('localhost', 'root', '');
if (!$con)
{
die('could not connect:'.mysql_error());
}
mysqli_select_db('job1');
Error: $sql = "INSERT INTO cc_job2 (cc_Answer_filename,cc_time,cc_workerID) VALUES
('".$_post["Answer_filename"]."','".$_post["track_data"]."','".$_post["workerID"]."')";
$result = mysqli_query($sql)
if ($result){
echo ("<br> Input data is succeed");
}else{
echo("<br> Input data is failed");
}
mysqli_close($con);
?>