gpt4 book ai didi

php - 分析错误 : syntax error, 意外 (T_VARIABLE)

转载 作者:行者123 更新时间:2023-11-29 01:13:13 24 4
gpt4 key购买 nike

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

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 查询后,它基本上什么都不喜欢

编辑:

我知道这很容易发生 SQL 注入(inject),但我这样做只是为了测试目的。

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

最佳答案

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

$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


解决方案?

只需用键盘和手指写下语句 new。

关于php - 分析错误 : syntax error, 意外 (T_VARIABLE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28952930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com