解析错误:语法错误,意外的(T_VARIABLE) [英] Parse error: syntax error, unexpected (T_VARIABLE)
问题描述
我正在执行一些查询,并收到以下错误消息:
I am executing some queries and am getting the following the error:
解析错误:语法错误,在线上出现意外的'$ section2'(T_VARIABLE) 22
Parse error: syntax error, unexpected '$section2' (T_VARIABLE) on line 22
第22行是:
$section2 = $db->prepare("INSERT INTO learning_style_scores VALUES (5,12,4)");
我不知道为什么得到这个,我已经检查了我的语法,而且一切似乎都是正确的. $section1
查询执行后,基本上什么都不喜欢
I don't have a clue why I am getting this, I have checked my syntax and all seems to be correct. It basically doesn't like anything after the $section1
query is executed
我知道这很容易进行SQL注入,但是我这样做只是出于测试目的.
I understand this is prone to SQL injection but I am doing it like this for testing purposes only.
<?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();
?>
推荐答案
您的代码在此行的分号后面有一些奇怪的字符:
Your code has some weird characters after the semicolon of this line:
$section1->execute();
$section2->execute(); //same for this line
如果您查看十六进制编辑器,则会看到以下内容:
If you look into a hex editor you see this:
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
在这里看到:
(是的,我知道我的圈子不是最好的)
(Yeah I know my circles aren't the nicest)
这应该是这样的:
解决方案?
只需用键盘和手指写下新的语句即可.
Just write the statement new with your keyboard and your fingers.
这篇关于解析错误:语法错误,意外的(T_VARIABLE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!