I have a bookings.php page that has a jqgrid that displays all the orders that were made on the Internet. When you double-click on a line, the jq dialog opens, which displays all the booking details. In addition, when you double-click, I have a specific variable, which is a link to the reservation that I want to pass to the php script:
var brData = rowData['bookref'];
I send this variable via 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); } }); }
Here is the switch case for all.inc.php:
case 'getDGRow': //header('Content-type: text/xml'); DatagridController::getGridRow($_REQUEST['rowdata']); break;
This is the PHP function that I am sending the jquery variable to for use in my PHP code:
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; } }
I put echo $ rowdata; in a PHP function to find out if a variable is being passed, which I see in BRB4345 in the firebug console. The problem is that this request:
$query = ("SELECT * FROM tblbookings WHERE bookref = '$rowdata'");
does not get any results. If I were to put:
$query = ("SELECT * FROM tblbookings WHERE bookref = 'BR12345'");
it retrieves the results that I need, so I canβt understand why this query does not work when the brData variable is passed to $ rowdata p>
Any suggestions?