我有一个 bookings.php 页面,其中有一个 jqgrid,显示所有在线预订。当您双击一行时,这将打开一个 jq 对话框,其中显示有关该预订的所有详细信息。此外,当您双击时,我定义了一个变量,它是我要传递给 php 脚本的预订参考:
var brData = rowData['bookref'];
我通过 ajax 发送这个变量:
function getGridRow(brData) {
$.ajax({
// Request sent from control panel, so send to cp.request.php (which is the handler)
url: 'scripts/php/bootstrp/all.request.php',
type: 'GET',
// Build data array - look at the '$_REQUEST' parameters in the 'insert' function
data: {
//ft: "getDGRow",
rowdata: 'fnme=getDGRow&row_data='+brData,
data: brData,
// Either pass a row id as the 'id' OR a where clause as the 'condition' never both
id: null,
condition: null
},
dataType: 'text',
timeout: 20000,
error: function(){
alert("It failed");
$('#cp-div-error').html('');
$('#cp-div-error').append('<p>There was an error inserting the data, please try again later.</p>');
$('#cp-div-error').dialog('open');
},
success: function(response){
// Refresh page
// response = brData;
// alert(response);
}
});
}
这是 all.inc.php 的 switch 案例:
case 'getDGRow':
//header('Content-type: text/xml');
DatagridController::getGridRow($_REQUEST['rowdata']);
break;
这是我将 jquery 变量发送到的 PHP 函数,以在我的 PHP 代码中使用:
public static function getGridRow($rowdata) {
$rowdata = $_GET['data'];
echo $rowdata;
$pdo = new SQL();
$dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);
try {
$query = ("SELECT * FROM tblbookings WHERE bookref = '$rowdata'");
$stmt = $dbh->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_BOTH);
BookingDocket::set_id($row['id']);
BookingDocket::set_bookref($row['bookref']);
BookingDocket::set_bookdate($row['bookingdate']);
BookingDocket::set_returndate($row['returndate']);
BookingDocket::set_journeytype($row['journeytype']);
BookingDocket::set_passtel($row['passengertel']);
BookingDocket::set_returndate($row['returndate']);
$stmt->closeCursor();
}
catch (PDOException $pe) {
die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
}
$dbh = null;
}
}
我已经把 echo $rowdata; 在 PHP 函数中查看是否正在传递变量,因为我可以在 firebug 控制台中看到“BR12345”。问题是这个查询:
$query = ("SELECT * FROM tblbookings WHERE bookref = '$rowdata'");
没有获取任何结果。如果我要说:
$query = ("SELECT * FROM tblbookings WHERE bookref = 'BR12345'");
它确实获取了我需要的结果,所以我不明白为什么当变量 brData 被传递给 $rowdata 时这个查询不起作用
有什么建议么?