执行查询时,PHP解析错误



这应该是一个非常基本的错误,但是基于错误描述,我似乎无法弄清楚它。我要么误解了该概念的某些部分,要么只是缺少一些迹象。

当我尝试执行查询时出现问题。

这是一些代码(我认为应该足够):

//Create database connection to my server
$pdo = new PDO($dsn, $user, $password);

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
//All single variables
$lan = $_POST["lan"];
$botyp = $_POST["botyp"];
//All variables with min and max value
$pris = $_POST["pris"];
$prisArray = explode(",", $pris); //Splits string "minvalue, maxvalue" by delimiter "," to become array with [minvalue, maxvalue]
$prisMin = $prisArray[0];
$prisMax = $prisArray[1];
$storlek = $_POST["storlek"];
$storlekArray = explode(",", $storlek);
$storlekMin = $storlekArray[0];
$storlekMax = $storlekArray[1];
$rum = $_POST["rum"];
$rumArray = explode(",", $rum);
$rumMin = $rumArray[0];
$rumMax = $rumArray[1];
$avgift = $_POST["avgift"];
$avgiftArray = explode(",", $avgift);
$avgiftMin = $avgiftArray[0];
$avgiftMax = $avgiftArray[1];
$query = "SELECT * FROM bostader 
WHERE lan = ? AND
objekttyp = ? AND
(pris >= ? AND pris <= ?) AND
(area >= ? AND area <= ?) AND
(rum >= ? AND rum <= ?) AND
(avgift >= ? AND avgift <= ?)";
$stmt = $pdo->prepare($query);
$stmt->execute([$lan, $botyp, $prisMin, $prisMax, $storlekMin, $storlekMax, $rumMin, $rumMax, $avgiftMin, $avgiftMax]); //Execute query using relevant variables

当我运行此问题时,我会发现一个错误:

解析错误:解析错误,在/library/webserver/documents/resultat.php上期望`']''行58

指向这一行的哪个:

$stmt->execute([$lan, $botyp, $prisMin, $prisMax, $storlekMin, $storlekMax, $rumMin, $rumMax, $avgiftMin, $avgiftMax]);

预先感谢您的帮助。

而不是此代码

$stmt->execute([$lan, $botyp, $prisMin, $prisMax, $storlekMin, $storlekMax, $rumMin, $rumMax, $avgiftMin, $avgiftMax]); 

您摇摇晃晃地尝试这个

$stmt->execute(array(
    $lan, 
    $botyp, 
    $prisMin, 
    $prisMax, 
    $storlekMin, 
    $storlekMax, 
    $rumMin, 
    $rumMax, 
    $avgiftMin, 
    $avgiftMax
)); 

相关内容

  • 没有找到相关文章

最新更新