I have 2 buttons, approve and reject to update booking status. I am lost when trying to pass value to approve_booking.php. Have no idea how to update single row according to bookingID. Need help on coding!!!
index.php
<head>
<script src="jquery-latest.js" type="text/javascript"></script>
<script src="jquery.tablesorter.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("#myTable").tablesorter({widgets: ['zebra']});
});
$(document).ready(function()
{
$("#myTable").tablesorter();
}
);
$(document).ready(function()
{
$("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );
}
);
</script>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="stylelogin.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" method="post" action="approve_booking.php" >
<?php
$db = new mysqli("localhost", "root", "", "eventdb");
$query = "SELECT customer.companyName, customer.contactName,eventinfo.eventTitle,boothAlias,date, testbook.bstatus, testbook.username, bookingID from eventinfo, testbook, customer where testbook.username=customer.username AND testbook.eventID=eventinfo.eventID";
$result = $db->query($query, MYSQLI_STORE_RESULT);
$o = '<table id="myTable" class="tablesorter" width="660px"><thead><tr><th>Company Name</th><th>Contact Name</th><th>Event</th><th>Booth</th><th>Date</th><th>Status</th></tr></thead><tbody>';
while(list($companyName, $contactName, $eventTitle, $boothAlias, $date, $bstatus,$bookingID) = $result->fetch_row()) {
if($bstatus==0){
$status="Pending";
}else if($bstatus==1){
$status="Successful";
}else{
$status="Reject";
}
$o .= '<tr><td width="120px">'.$companyName.'</td><td width="120px">'.$contactName.'</td><td width="180px">'.$eventTitle.'</td><td width="70px">'.$boothAlias.'</td><td width="170px">'.$date.'</td><td width="70">'.$status.'</td><td width="100"><input width="100px" name="APPROVED" type="submit" id="APPROVED" value="Approve"> <input width="100px" name="REJECT" type="submit" id="REJECT" value="Reject"></td></tr>';
}
$o .= '</tbody></table>';
echo $o;
?>
</form>
</body>
approve_booking.php
<?php
mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("eventdb") or die (mysql_error());
if(isset($_POST['APPROVED']))
{
$query2 = "UPDATE testbook SET bstatus ='0' WHERE bookingID='$_POST[booking]'";
$result2 = @mysql_query($query2);
}
if (isset($_POST['REJECT']))
{
$query3 = "UPDATE testbook SET bstatus ='2' WHERE bookingID='$_POST[booking]'";
$result3 = @mysql_query($query3);
}
?>
If booking id is your auto increament / primary key so it update only single row but if its not then use your primary key in WHERE condition so it can find and update only 1 row.
This is probably causing your problem.
snip
$query3 = "UPDATE testbook SET bstatus ='2' WHERE bookingID='$_POST[booking]'";
/snip
Change it to this:
snip
$query3 = "UPDATE testbook SET bstatus ='2' WHERE bookingID='{$_POST['booking']}'";
snip
Note that echoing post variables directly into query strings like these is highly unsecure. I suggest checking the variable first before putting it in there.
Anyway, your problem is the value of the variable $_POST['booking']
probably wasn't passed into the query. It passed the string $_POST['booking']
.
Hi i don't see any form fields in that form. create a hidden field with name of "booking"
<input type="text" name="booking" value="<?php echo $bookingID; ?>" >
Did you pass bookingID to php?
<input type="hidden" name="booking" id="booking">
add onclick
function to both bottons to save selected row's bookingid to a hidden input.
onclick=$(\"#booking\").val('.$bookingID .');