Php 分析错误:语法错误,意外';进入';(T_字符串)在第7行
我在运行这段代码时遇到了这个错误,我用它向数据库添加了一个特定的过滤器Php 分析错误:语法错误,意外';进入';(T_字符串)在第7行,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,我在运行这段代码时遇到了这个错误,我用它向数据库添加了一个特定的过滤器 <?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: " .
<?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);
?>
将$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']."')";
在您的$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']."');";
首先,您需要学习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);
就PHP而言,SQL查询应该是一个字符串,因此引用为字符串