运行此代码时出现此错误,即使用它来向数据库添加特定过滤器。
<?php
//Connect to Databaseeee
$con=mysqli_connect("127.0.0.1","root","Toom13371!","filter_database_test");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// sql insertationerino
$sql = INSERT INTO filterlist ('type_code', 'connector_type', 'construction_type', 'author', 'estimate_lead_time', 'last_update', 'confidence_level', 'passtype', 'start_passband', 'stop_passband', 'low_stopband', 'high_stopband', 'low_passband', 'high_passband', 'start_stopband', 'stop_stopband') VALUES ('".$_POST['type_code']."', '".$_POST['connector_type']."', '".$_POST['construction_type']."', '".$_POST['author']."', '".$_POST['estimate_lead_time']."', '".$_POST['last_update']."', '".$_POST['confidence_level']."', '".$_POST['passtype']."', '".$_POST['start_passband']."', '".$_POST['stop_passband`']."', '".$_POST['low_stopband']."', '".$_POST['high_stopband']."', '".$_POST['low_passband']."', '".$_POST['high_passband']."', '".$_POST['start_stopband']."', '".$_POST['start_stopband']."');
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 Filter Added";
mysqli_close($con);
?>
完整错误是:
解析错误:语法错误,意外&#39; INTO&#39;第7行的C:\ xampp \ htdocs \ html \ addprocess.php中的(T_STRING)
答案 0 :(得分:0)
将$ sql语句替换为:
$sql = "INSERT INTO filterlist ('type_code', 'connector_type', 'construction_type', 'author', 'estimate_lead_time', 'last_update', 'confidence_level', 'passtype', 'start_passband', 'stop_passband', 'low_stopband', 'high_stopband', 'low_passband', 'high_passband', 'start_stopband', 'stop_stopband') VALUES ('".$_POST['type_code']."', '".$_POST['connector_type']."', '".$_POST['construction_type']."', '".$_POST['author']."', '".$_POST['estimate_lead_time']."', '".$_POST['last_update']."', '".$_POST['confidence_level']."', '".$_POST['passtype']."', '".$_POST['start_passband']."', '".$_POST['stop_passband`']."', '".$_POST['low_stopband']."', '".$_POST['high_stopband']."', '".$_POST['low_passband']."', '".$_POST['high_passband']."', '".$_POST['start_stopband']."', '".$_POST['start_stopband']."')";
答案 1 :(得分:0)
如果您查看结尾,请在$sql = INSERT INTO
语句中"');
,这应该是"'");
。
你的sql查询也需要是一个字符串,你不能把它作为一个函数调用。所以把整个查询放在一个字符串中。所以它应该是:
$sql = "INSERT INTO filterlist ('type_code', 'connector_type', 'construction_type', 'author', 'estimate_lead_time', 'last_update', 'confidence_level', 'passtype', 'start_passband', 'stop_passband', 'low_stopband', 'high_stopband', 'low_passband', 'high_passband', 'start_stopband', 'stop_stopband') VALUES ('".$_POST['type_code']."', '".$_POST['connector_type']."', '".$_POST['construction_type']."', '".$_POST['author']."', '".$_POST['estimate_lead_time']."', '".$_POST['last_update']."', '".$_POST['confidence_level']."', '".$_POST['passtype']."', '".$_POST['start_passband']."', '".$_POST['stop_passband`']."', '".$_POST['low_stopband']."', '".$_POST['high_stopband']."', '".$_POST['low_passband']."', '".$_POST['high_passband']."', '".$_POST['start_stopband']."', '".$_POST['start_stopband']."');";
答案 2 :(得分:0)
首先,你需要学习php的基础知识。
尝试这样:
$sql = "INSERT INTO filterlist (`type_code`, `connector_type`, `construction_type`,
`author`, `estimate_lead_time`, `last_update`, `confidence_level`, `passtype`,
`start_passband`, `stop_passband`, `low_stopband`, `high_stopband`, `low_passband`,
`high_passband`, `start_stopband`, `stop_stopband`) VALUES
('".mysqli_real_escape_string($con,$_POST['type_code'])."',
'".mysqli_real_escape_string($con,$_POST['connector_type'])."',
'".mysqli_real_escape_string($con,$_POST['construction_type'])."',
'".mysqli_real_escape_string($con,$_POST['author'])."',
'".mysqli_real_escape_string($con,$_POST['estimate_lead_time'])."',
'".mysqli_real_escape_string($con,$_POST['last_update'])."',
'".mysqli_real_escape_string($con,$_POST['confidence_level'])."',
'".mysqli_real_escape_string($con,$_POST['passtype'])."',
'".mysqli_real_escape_string($con,$_POST['start_passband'])."',
'".mysqli_real_escape_string($con,$_POST['stop_passband`'])."',
'".mysqli_real_escape_string($con,$_POST['low_stopband'])."',
'".mysqli_real_escape_string($con,$_POST['high_stopband'])."',
'".mysqli_real_escape_string($con,$_POST['low_passband'])."',
'".mysqli_real_escape_string($con,$_POST['high_passband'])."',
'".mysqli_real_escape_string($con,$_POST['start_stopband'])."',
'".mysqli_real_escape_string($con,$_POST['start_stopband'])."')";
if (!mysqli_query($con,$sql)){
die('Error: ' . mysqli_error($con));
}
echo "1 Filter Added";
mysqli_close($con);