oraya Posted July 12, 2012 Share Posted July 12, 2012 Hi could someone tell me what I'm doing wrong. I've been trying to figure it out for a couple hours. I am trying to set up a page (Floral Catalogue) where the user can delete multiple entries in the database. The form has a checkbox that is used to delete the rows in the database. It works fine and deletes the items, but after the delete I get this error Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 38 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 39 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 40 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 41 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 42 It relates to where I set the variables for the data pulled in from the database. What am I doing wrong? Any help would be so gratefully received, as it's driving me nuts trying to figure out what I'm doing wrong. I know what the error means, well I'm pretty sure I do. It means that you have to have the database connection first before you set the variables. Or am I wrong? Anyway if anyone could help as I said I'd be so grateful . Oraya <?php $table = 'floral_catalogue'; //TABLE TO OPEN $title = 'Testing the multi-delete form.'; //PAGE TITLE include_once'_layout-header.php'; include_once'_dbconnect.php'; $query="SELECT * FROM $table"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <br /> <br /> <div class="title"><?php echo $title; ?></div> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <!-- HIDDEN FIELDS DO NOT EDIT --> <input type="hidden" name="table" value="<?php echo $table; ?>" /> <!-- END OF HIDDEN FIELDS --> <table> <tr> <td style="padding-left: 10px;">File:</td> <td style="padding-left: 10px;">Name:</td> <td style="padding-left: 10px;">Description</td> <td style="padding-left: 10px;">Delete:</td> </tr> <?php $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $location=mysql_result($result,$i,"location"); $name=mysql_result($result,$i,"name"); $description=mysql_result($result,$i,"description"); $image_file=mysql_result($result,$i,"image_file"); if(!isset($_POST['submitted'])){ ?> <tr> <td style="width: 75px; height: 75px; background-image: url(<?php echo $location . $image_file ?>); background-size:75px 75px;"> </td> <td style="width: 150px; height: 50px; padding-left: 10px;"> <?php echo $name; ?> </td> <td style="width: 390px; height: 50px; padding: 10px;"> <?php echo $description; ?> </td> <td style="width: 75px; height: 75px; vertical-align: middle; text-align: center; background-color: #F6F4F2;"> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $id; ?>" /> </td> </tr> <?php }else{ include_once'_dbconnect.php'; $table = mysql_real_escape_string( $_POST["table"] ); $del_checkbox = $_POST['checkbox']; $del_items = implode(",", $del_checkbox); $sql="DELETE FROM $table WHERE id IN ($del_items)"; $result = mysql_query( $sql ) or die( mysql_error() ); } $i++; } // END OF THE LOOP ?> <input type="submit" name="submitted" value="Delete Selected Items" class="button" /> <div class="clearer"></div> </table> <input type="submit" name="submitted" value="Delete Selected Items" class="button" /> </form> <?php mysql_close(); include_once'_layout-footer.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/265581-deleting-multiple-entries-getting-error/ Share on other sites More sharing options...
samshel Posted July 12, 2012 Share Posted July 12, 2012 use mysql_error(); $result=mysql_query($query) or die(mysql_error()); This is the first step that will tell you if your query is getting executed correctly. Quote Link to comment https://forums.phpfreaks.com/topic/265581-deleting-multiple-entries-getting-error/#findComment-1361145 Share on other sites More sharing options...
oraya Posted July 12, 2012 Author Share Posted July 12, 2012 I'm sorry really new to php, I thought I had. If not would you mind giving me an example of how to write it. Would it be just: $result=mysql_error(); Oraya Quote Link to comment https://forums.phpfreaks.com/topic/265581-deleting-multiple-entries-getting-error/#findComment-1361147 Share on other sites More sharing options...
PFMaBiSmAd Posted July 12, 2012 Share Posted July 12, 2012 Your code inside of the while(){} loop is reusing the $result variable, so after the first pass through the loop, $result no longer contains the result resource from the select query. Make sure you know which variable you are using where. Quote Link to comment https://forums.phpfreaks.com/topic/265581-deleting-multiple-entries-getting-error/#findComment-1361148 Share on other sites More sharing options...
oraya Posted July 12, 2012 Author Share Posted July 12, 2012 I thought that was what was happening, so how should I go about altering my code to stop the error? Quote Link to comment https://forums.phpfreaks.com/topic/265581-deleting-multiple-entries-getting-error/#findComment-1361150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.