Page 1 of 1

Help

Posted: Fri Sep 10, 2010 9:35 pm
by dvidunis
im making mail like site using mysql, i have a working mysql_fetch_assoc() while that displays correctly. i made a single delete page it worked, but i want multiple delete with checkboxes please help. if you can please dont use javascript im bad im javascript. heres the code:

Code: Select all

<?php
include ("template.php");
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("wmail") or die(mysql_error());
$to = $_SESSION['email'];
// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM email WHERE account='$to'")
or die(mysql_error());
$result_num_rows = mysql_num_rows($result);
?>
<form method="post" action="searchinbox.php">Search: <input type="text" name="scontents"> <input type="submit" name="submit" value="Search"></form>
<?php
echo "<table border='3'>";
echo "<tr> <th>*</th> <th>From</th> <th>Subject</th> <th>Actions</th> </tr>";
// keeps getting the next row until there are no more to get
$rowcount = '0';
$unrowcount = '0';
while($row = mysql_fetch_array( $result )) {
           $bolt1 = "";
           $bolt2 = "";
           $numberzero = "0";
           $rowunread = $row['read'];
           if ($rowunread == $numberzero){

           $bolt1 = "<b>";
           $bolt2 = "</b>";
           $unrowcount++;
           }
           // Print out the contents of each row into a table
           echo "<tr><td>";
           echo "<input type='checkbox' name='checked'><br />";
           echo "</td><td>";
           echo "".$bolt1."".$row['sender']."".$bolt2."";
           echo "</td><td>";
           echo "".$bolt1."".$row['subject']."".$bolt2."";
           echo "</td><td>".$bolt1."<a href='http://5.4.206.216/wmail/message.php?id=".$row['id']."'>View</a> - <a href='http://5.4.206.216/wmail/delmail.php?id=".$row['id']."'>DELETE!</a></td></tr>".$bolt2."";
           $rowcount++;
}

echo "</table>";
$readcount = $rowcount-$unrowcount;
echo "You Have ".$rowcount." Mails in total, ".$unrowcount." Unread, ".$readcount." Read.";
if ($result_num_rows = 0)
  echo "<br><b>No mail!</b>";
$redirect = '<meta HTTP-EQUIV="REFRESH" content="0; url=http://5.4.206.216/Wmail/index.php">';
if (isset($_SESSION["email"]))
$redirect = '';
echo $redirect;
?>
Please Help! :bow: :bow: :bow:

Re: Help

Posted: Sat Sep 11, 2010 12:50 am
by Christopher
Make your URL like this and you will receive and array of values in $_GET['id'].

Code: Select all

"http://5.4.206.216/wmail/delmail.php?id[]=".$row['id']

Re: Help

Posted: Sat Sep 11, 2010 7:23 am
by dvidunis
Christopher wrote:Make your URL like this and you will receive and array of values in $_GET['id'].

Code: Select all

"http://5.4.206.216/wmail/delmail.php?id[]=".$row['id']
can you give me the whole code? it wont work, im a new to php and im 11 years old, so where is the checkboxes? i wanted checkboxes
please help :(

Re: Help

Posted: Sun Sep 12, 2010 2:04 pm
by Jonah Bron
Surround the HTML table with a <form>, and put a checkbox in each row wherever you want it, and give it the name "id[]". Then in delmail.php, instead of deleting $_GET['id'] like you are now, $_GET['id'] will be an array, and you'll loop through it with foreach.

Code: Select all

// simple example
if (!isset($_GET['id'])) {
    die('Nothing to delete.');
}
foreach ($_GET['id'] as $email) {
    //$email is the ID of the email.  delete it.
}