Can someone please help? Here is my jQuery. The scenario is this, I have a table where it has a button on with every <td>.If you click that button a modal window will appear with a confirmation button on it with yes or no. If the user clicks yes (#confirm_cancel), this will save in the database then show an alert box wherein it tells the users that the update was successful. The problem is this, it properly executes my SQL and saves to the database but I get an alert box on error function that says [object object].
This is my PHP:
<?php
include("php/openDB.php");
echo '<table border="2" id="tableGuestList">';
echo '<tr>';
echo '<td>Guest ID</td>';
echo '<td>Room No:</td>';
echo '<td>First Name</td>';
echo '<td>Last Name</td>';
echo '<td>Checkin</td> ';
echo '<td>checkout</td>';
echo '<td>Status</td>';
echo '</tr>';
$result = mysql_query("SELECT gi.guest_id, gi.fname, gi.lname, bk.checkin, bk.checkout, bk.transacstatus, bk.reserved_id "
."FROM tbl_guestinfo gi, tbl_bookings bk "
."where gi.guest_id = bk.guest_id "
."AND bk.transacstatus = 'booked'");
while ($rows = mysql_fetch_array($result, MYSQL_NUM)) {
$guest_id = $rows[0];
$fname = $rows[1];
$lname = $rows[2];
$checkin = $rows[3];
$checkout = $rows[4];
$transacstatus = $rows[5];
$reservedid = $rows[6];
echo '<tr id="'.$rows[0].'" class="bookedClass">';
echo '<td>'.$guest_id.'</td>';
echo '<td> room number kaara</td>';
echo '<td> '.$fname.'</td>';
echo '<td>'.$lname.'</td>';
echo '<td> '.$checkin.'</td>';
echo '<td>'.$checkout.'</td>';
echo '<td> '.$transacstatus.'</td>';
echo '<td style="display:none"> '.$reservedid.'</td>';
echo '<td> <input type = "submit" value = "Cancel Booking" name ="cancel_booking" /></td>';
echo '<td> <input type = "submit" value = "Check in" name ="check_in" /></td>';
//echo '<td> <input type = "submit" value = "Check Out" name ="Check_Out" /></td>';
echo '</tr>';
}
mysql_free_result($result);
echo '</table>';
include("php/closeDB.php");
?>
this is my jquery
$(document).ready(function(){
var selGuest;
$('#tableGuestList .bookedClass').click(function(){
selGuest = $(this).find("td").eq(7).text();
selGuest = parseInt(selGuest)
$('#confirmDialog').fadeIn('slow');
});
$('#confirm_cancel').click(function() {
var canceldata_json = {
'selGuest': selGuest,
};
$.ajax({
type: "POST",
data: canceldata_json,
url: "./php/cancelBooking.php",
success: function(msg) {
alert("guest information updated")
$('#confirmDialog').fadeOut('slow');
},
error: function(msg){
alert(msg)
}
});
});
$('#cancel_cancel').click(function() {
$('#confirmDialog').fadeOut('slow');
});
});
and here is my PHP code being called by the AJAX
<?php
// get data
$selGuest = $_POST["selGuest"];
include("openDB.php");
$insertintoCanceled = "insert into tbl_canceled "
."reserved_id, `guest_id`,`checkin`, `checkout`, `type_id`, `numAdults`, `numChildren`, `transacstatus`, `amountDue`"
."("
."SELECT * FROM `tbl_bookings` where `reserved_id` =" .$selGuest
.")";
if(!mysql_query($insertintoCanceled, $con))//if it fails
{
die('Error: ' . mysql_error() . "\n");//show the mysql error
}
include("closeDB.php");
?>
This may be caused by
alert(msg).msgmay be an object, and the actual data you want is one of its property values. Try setting a breakpoint within Chrome dev tools or Firebug within the error function and inspecting what valuemsgcontains. It may be as simple as usingalert(msg.d)instead.