我已经使用了一个预准备语句来定义id索引,但它告诉我它由于某种原因未定义,我在哪里以及为了这个而改变了什么?
<?php
$db_username='student';
$db_password='student';
$db = new PDO ('mysql:host=192.168.56.2;dbname=Assessment', $db_username, $db_password);
$result = $db ->prepare("SELECT * FROM Jobs WHERE jobname='".$_GET['id']."' ");
$result->execute();
答案 0 :(得分:1)
试试这个:
<?php
$db_username='student';
$db_password='student';
$db = new PDO ('mysql:host=192.168.56.2;dbname=Assessment', $db_username, $db_password);
if(isset($_GET['id'])) {
$result = $db ->prepare("SELECT * FROM Jobs WHERE jobname=?");
$result->execute(array($_GET['id']);`enter code here
}
else {echo('$_GET["id"] not set');}
答案 1 :(得分:0)
首先,验证$ _GET ['id']是否有值。其次,为了安全起见,改变一些方面:
$result = $db ->prepare("SELECT * FROM Jobs WHERE jobname=:id");
$result->execute(array(':id' => $_GET['id']));