Jump to content

checkboxes


tommy168

Recommended Posts

Hey guys

 

I am confused about using checkboxes to delete entries. Yes, just for delete.

 

Codes for table:

 

echo "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">
<table>
<tr>
<td width=\"55\" class=\"formLabelsS2\"><input type=\"submit\" name=\"delete\" value=\"Delete\" id=\"delete\"></td>
<td> Please note that entries could not be restored once they are deleted!</td>
</tr>
</table>
</form>";


echo "<table class=\"sortable\" id=\"query_quick1\" width=\"100%\" >\r\n";
echo "<thead>";
echo "\t<tr><th></th><th></th><th>Up.dated Query</th><th>Link</th><th>Promoter</th><th> # </th><th>Up?</th>
<th>Ana. Area</th><th> # </th><th>Up?</th>
<th>C. Type</th><th> # </th><th>Up?</th><th>Other C. Type</th>
<th> # </th><th>Up?</th><th>Gen. Back.</th><th> # </th><th>Up?</th>
<th>Other Gen. Back.</th><th> # </th><th>Up?</th><th>Author</th><th> # </th><th>Up?</th>
<th>Other</th><th> # </th><th>Up?</th><th>Date</th><th>Email</th>
<th>F. Name</th><th>L. Name</th></tr>\r\n";
echo "</thead>";


if($result->num_rows){
while ($row = $result->fetch_array()){
$RowCount ++;
$row_color = ($RowCount % 2) ? $color1 : $color2;
echo "\t<tr class=\"$row_color\" >

<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">
<td><input type =\"hidden\" name = \"id\" value=\"{$row['id']}\"></td>
<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$rows['id']} \"></td>

<td>{$row['query']}</td><td>{$row['link']}</td>
<td>{$row['pro']}</td><td>{$row['pro_count']}</td>
<td>{$row['pro_update']}</td>
<td>{$row['ana']}</td><td>{$row['ana_count']}</td><td>{$row['ana_update']}</td>
<td>{$row['cell']}</td><td>{$row['cell_count']}</td><td>{$row['cell_update']}</td>
<td>{$row['cellother']}</td><td>{$row['cellother_count']}</td><td>{$row['cellother_update']}</td>
<td>{$row['gen']}</td><td>{$row['gen_count']}</td><td>{$row['gen_update']}</td>
<td>{$row['genother']}</td><td>{$row['genother_count']}</td><td>{$row['genother_update']}</td>
<td>{$row['author']}</td><td>{$row['author_count']}</td><td>{$row['author_update']}</td>
<td>{$row['other']}</td><td>{$row['other_count']}</td><td>{$row['other_update']}</td>
<td>{$row['date']}</td><td>{$row['Email']}</td>
<td>{$row['First_Name']}</td><td>{$row['Last_Name']}</td>
</form></tr>";
}
}
echo "</table>"; 

 

php for deleting entries:

 

 

} elseif(isset($_SESSION['user_id']) AND isset($_POST['delete'])){

$connect=db_connect_2();

foreach($_POST['checkbox'] as $check)
{
$delete = mysqli_query("DELETE FROM mailing_list WHERE id = '$check'");
}
$body = "mailingList.php";
} 

 

Error pops up:

 

Warning: Invalid argument supplied for foreach()

 

 

Of course no entries are deleted due to this warning.

 

Help would be greatly appreciated as always

 

Thanks.

Link to comment
Share on other sites

I may not be up on the latest things that HTML can do, but it looks like you are mixing php and html without ending and closing tags (<?php and ?>).  Granted, you can use things like while loops and if statements with HTML, but you have to do it like so:

 

<?php if (condition): ?>
<html tags> content <more tags>
<?php endif; ?>

 

Also, you use rows['id'] at one point and row['id'] at another - one with an s and one without.

 

The main error you are getting, however, is that foreach is supplied a non array to iterate, I believe.  Looking through the code, I only see one input attached to the name "checkbox" and then in the PHP you are trying to iterate through an array of that name.  Oh, this is the line that uses the checkbox name, and the only one that I saw:

 

<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$rows['id']} \"></td>

Link to comment
Share on other sites

I may not be up on the latest things that HTML can do, but it looks like you are mixing php and html without ending and closing tags (<?php and ?>).  Granted, you can use things like while loops and if statements with HTML, but you have to do it like so:

 

<?php if (condition): ?>
<html tags> content <more tags>
<?php endif; ?>

 

Also, you use rows['id'] at one point and row['id'] at another - one with an s and one without.

 

The main error you are getting, however, is that foreach is supplied a non array to iterate, I believe.  Looking through the code, I only see one input attached to the name "checkbox" and then in the PHP you are trying to iterate through an array of that name.  Oh, this is the line that uses the checkbox name, and the only one that I saw:

 

<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$rows['id']} \"></td>

 

You can echo html from php without any problems. The name attribute, specified as checkbox[], makes it an array.

Link to comment
Share on other sites

Oh, I see what he was doing.  I'm used to seeing echo'd lines looking like this:

 

echo "blah blah"

      ."more html";

 

It's confusing to see the tags in there without quotes to start out like the convention above.  I see the where the quotes begin and end now, though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.