解析错误:语法错误,意外(T_VARIABLE)

时间:2015-03-09 22:29:45

标签: php mysql

我正在执行一些查询,并收到以下错误:

  

解析错误:语法错误,意外的'$ section2'(T_VARIABLE)在线   22

第22行是:

$section2 = $db->prepare("INSERT INTO learning_style_scores VALUES (5,12,4)");

我不知道为什么我得到这个,我检查了我的语法,一切似乎都是正确的。在$section1查询执行后,它基本上不喜欢任何内容

修改

我知道这很容易被SQL注入,但我这样做是为了测试目的。

<?php
    session_start();

    try {
    $db = new PDO("mysql:dbname=questionnaire;host=localhost", "root", ""); 
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    }


    catch(Exception $e)
    {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }


    $session = md5(session_id());

    // insert section1 data into database
    $section1 = $db->prepare('INSERT INTO section1 VALUES (7,"test")');

    $section1->execute();​


    // insert learning style score into database
    $section2 = $db->prepare("INSERT INTO learning_style_scores VALUES (5,12,4)");

    $section2->execute();​
    ?>

1 个答案:

答案 0 :(得分:8)

您的代码在此行的分号后面有一些奇怪的字符:

$section1->execute();​
$section2->execute();​  //same for this line

如果您查看十六进制编辑器,您会看到:

24 73 65 63 74 69 6f 6e 31 2d 3e 65 78 65 63 75 74 65 28 29 3b e2 80 8b  
                                                             //^^^^^^^^This bit right here

//And it should look like this:
24 73 65 63 74 69 6f 6e 31 2d 3e 65 78 65 63 75 74 65 28 29 3b  

见这里:

enter image description here

(是的,我知道我的圈子不是最好的)

这就是它应该是这样的:

enter image description here


解?

只需用键盘和手指写下新的声明。

相关问题