I am hoping someone can point me in the right direction. I have tried various permutations and receiving the same error each time of "Error: Query was empty". I have to tell you that I am not in anyway a programmer and just trying to adapt an existing application on my own. I will be happy to provide a live location for viewing the site layout and what I am trying to achieve. (pm me for the site location and login details if you want to view the site)...
Essentially the site allows small guesthouses to register their accommodation establishment and to manage bookings etc from there. One of the things they can do is to enter their rates. The application never had any functionality for them to delete any rates and this is what I am attempting to insert, functionality that will allow a vendor to select a rate for deletion using a checkbox.
My code is currently as follows. On clicking the delete button I receive an error:Query was empty. I have a feeling that I am going wrong on marrying the checkbox id to the record id but for the life of me I cant get it right...
Hope someone can assist... am sure it is staring me in the face but after two days of trying still cannot see the wood for the trees...
p.s. Some of the code lines are commented out... this is because it was various things I was trying out and getting errors from but kept them there for later referral if need be
<?php $rates = dbGetRows("rates", "venueid = '".$_SESSION['venueid']."' ORDER BY roomtype, datefrom"); //$result=mysql_query($rates); //$count=mysql_num_rows($result); $roomtypes = dbGetRows("roomcategories", "venueid = '".$_SESSION['venueid']."'"); $id = dbGetRows("rates", "id = '".$_SESSION['venueid']."'"); //while ($row = mysql_fetch_assoc($result)){ if($_POST['delete']) // from button name="delete" { $checkbox = $_POST['checkbox']; //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($i=0;$i<$countCheck;$i++) { $del_id = $checkbox[$i]; $sql = "DELETE FROM rates where rates.id = $del_id"; $result = mysql_query($query) or die( "Error: " . mysql_error() ); } if($result) { header('Location: index.php?section=rates'); } else { echo "Error: ".mysql_error(); } } ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="small"> <font size="3"><b><?php echo $venue['venuename']." "; ?> - Rates Setup</b></font><br> The rate data entered here is used to determine the cost of a guest's accommodation at your establishment.<br> If you wish to discount your rates to certain groups, clicking on 'Manage Rate Groups' will set this up.<br> <br> <a href="javascript:;" onclick="window.open('rategroups.php', '_blank', 'width=500,height=350,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');">[Manage Rate Groups]</a> <br> <br> <a href="javascript:;" onclick="<?php if( mysql_num_rows($roomtypes) == 0 ) echo "alert('Rates information cannot be entered without room/unit categories existing.\\nPlease setup your rooms or units first');"; else echo "window.open('newratewizard.php', '_blank', 'width=700,height=500,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');";?>">[Add New Rate]</a>- <a href="javascript:;" onclick="window.open('delrates.php', '_blank', 'width=900,height=350,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');">[Delete Rates]</a> <br> <br> <form id="form1" name="form1" method="post" action=""> <p> <?php $oldroomtype = ""; while( $rate = mysql_fetch_array($rates, MYSQL_ASSOC) ) { $roomtype = $rate['roomtype']; $id = $rate['id']; if( $roomtype != $oldroomtype ) { $roomcategories = dbGetRows("roomcategories", "id = '".$roomtype."'"); $roomcategory = mysql_fetch_array($roomcategories, MYSQL_ASSOC); $roomtypename = $roomcategory['roomname']; if( $oldroomtype != "" ) echo "</table><br><br>"; echo "<b>".strtoupper($roomtypename)."</b> <table width=\"600\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" style=\"border: 1px solid #EEEEEE;\"> <tr bgcolor=\"#DDDDDD\"> <td class=\"small\" align=\"center\"><b>DESCRIPTION</b></td> <td class=\"small\" align=\"center\"><b>PERIOD</b></td> <td class=\"small\" colspan=\"56\" align=\"center\"><b>RATES</b></td> </tr> <tr> <td class=\"small\"> </td> <td class=\"small\"> </td> <td class=\"small\" align=\"center\" bgcolor=\"#E4E4E4\"><b>Single</b></td> <td class=\"small\" align=\"center\" bgcolor=\"#E4E4E4\"><b>Double</b></td> <td class=\"small\" align=\"center\" bgcolor=\"#E4E4E4\"><b>Child</b></td> <td class=\"small\" align=\"center\" bgcolor=\"#E4E4E4\"><b>Infant</b></td> <td class=\"small\" align=\"right\" width=\"1\" bgcolor=\"#E4E4E4\"></td> <td class=\"small\" align=\"center\" bgcolor=\"#E4E4E4\"><b>Base Rate</b></td> </tr>"; $oldroomtype = $roomtype; } echo "<tr bgcolor=\"#F5F5F5\"> <td class=\"small\">".$rate['ratename']."</td> <td class=\"small\" class=\"small\" align=\"center\">".date("d M Y", myDateTophp($rate['datefrom']))." - ".date("d M Y", myDateTophp($rate['dateto']))."</td> <td class=\"small\" align=\"center\">".($rate['single'] > 0 ? $rate['single'] : "")."</td> <td class=\"small\" align=\"center\">".($rate['double'] > 0 ? $rate['double'] : "")."</td> <td class=\"small\" align=\"center\">".($rate['child'] > 0 ? $rate['child'] : "")."</td> <td class=\"small\" align=\"center\">".($rate['infant'] > 0 ? $rate['infant'] : "")."</td> <td class=\"small\" align=\"center\" width=\"1\" bgcolor=\"#E4E4E4\"></td> <td class=\"small\" align=\"center\">".($rate['base'] > 0 ? $rate['base'] : "")."</td> <td class=\"small\" align=\"center\">".($rate['id'] > 0 ? $rate['id'] : "")."</td> <td><input type='checkbox' name='checkbox[]' id='checkbox[]' value=$del_id </td> </tr>"; } if( mysql_num_rows($rates) > 0 ) echo " </table> "; ?> </p> <p><label><input type="submit" name="delete" id="button" value="Delete Selected" /></label></p> </form> </td> </tr> </table>