php 解析错误:语法错误,第 7 行出现意外的“INTO”(T_STRING)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25199444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:43:47  来源:igfitidea点击:

Parse error: syntax error, unexpected 'INTO' (T_STRING) on line 7

phpmysqlphpmyadmin

提问by thomasward1212

I get this error when running this code, im using it to add a specific filter to a database.

运行此代码时出现此错误,我使用它向数据库添加特定过滤器。

       <?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);
        ?>

The full error is:

完整的错误是:

Parse error: syntax error, unexpected 'INTO' (T_STRING) in C:\xampp\htdocs\html\addprocess.php on line 7

解析错误:语法错误,第 7 行 C:\xampp\htdocs\html\addprocess.php 中出现意外的“INTO”(T_STRING)

回答by v2solutions.com

Replace your $sql statement to:

将您的 $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']."')";

回答by v2solutions.com

In your $sql = INSERT INTOstatement if you look at the end, you have "');, this should be "'");. Also your sql query needs to be a string, you cannot have it as a function call. So put the whole query inside a string. So it should be:

在你的$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']."');";

回答by Awlad Liton

First of all you need to learn basic of php.

首先你需要学习php的基础知识。

  • Any string should be inside quotation.
  • You'll need to escape the values before you put them into query by using mysqli_real_escape_string()
  • 任何字符串都应该在引号内。
  • 在使用mysqli_real_escape_string()将它们放入查询之前,您需要对这些值进行转义

try like this:

试试这样:

$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);