Jump to content

Deleting multiple entries getting error!


oraya
 Share

Recommended Posts

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';
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.