Jump to content

Not very Simple question but here its is .. its about checkbox's form/delete d..


Monshery

Recommended Posts

Well basicaly i am trying to make a Admin side of my data base show thats means that php basicaly will print all the lines 1 by 1 in dec order and show them what i am trying to do and cant figure out whats not working is .. i added a check box in every fatch array .... and i am trying to make an array with this check box so i could delete several massages at once if i want here here is the exact code :
[code]
 
<?php
// well basicaly if i make this to work i will know how to delete enough that i will know that i can send me //the array but somewhy it wont send me.
  foreach ($_POST["checkbox"] as $key=>$val)
    echo "key:$key value:$val<BR>\n";
?>
  <table width="444" border="0">

  <tr>

    <td height="23"><div align="left"><span class="style3">my admin</span></div><div align="right"><span class="style5">הודעות מעודכנות להיום</span></div></td>

  </tr>

  <tr>
    <td width="438" height="33" bgcolor="#006699">    <form action="Admin.php" method="POST">
        <table width="437" border="0" style="border-width: 0px">

        <tr>

          <td bgcolor="#FFFFFF" class="style1" style="border-style: none; border-width: medium">

<!-- php database -->

<?php
$post_LINK=mysql_connect('xxxxxxxxx','xxxxxxxx','xxxxxxx') or die("Connection fail");
mysql_select_db('xxxxxxxxx',$post_LINK);
$MASSAGES_links = mysql_query("SELECT * FROM xxxxxxx ORDER BY id DESC",$post_LINK);
while($MASSEGES=mysql_fetch_array($MASSAGES_links))
{
?>

            <div align="right"></div>

            <div align="right">

              <table width="432" height="77" border="0" bgcolor="#FFFFFF">

                  <tr>

                    <td width="167" height="23">
                      <div align="left">

<input type="checkbox" name="checked[<?php print $MASSEGES['id']; ?>]" value="<?php print $MASSEGES['id'];?>">                       
למחיקת הודעה סמן </div></td>

                    <td width="167"><div align="right"><?php echo $MASSEGES['name'];?></div></td>
                    <td width="30"><div align="right">:שם 

                    </div></td>

                    <td width="52"><div align="right"><?php echo $MASSEGES['id'];?>

                    </span></div></td>

                  </tr>

                  <tr>

                    <td height="23" colspan="3"><div align="right"><?php echo $MASSEGES['email'];?></div>

                      <div align="right"></div></td>

                    <td height="23"><div align="right">: נושא</div></td>

                  </tr>

                  <tr>

                    <td height="23" colspan="4"><p align="right">:הודעה</p>
                    <p align="right"><?php echo $MASSEGES['massage'];?></p>

                      <p align="right">----------------------------------------------------------------------------------- </p></td>

                  </tr>

              </table>

              <?php } ?>

            </div></td>

        </tr>

      </table> <input name="deletem" type="submit" id="deletem" value="מחק את ההודעות">
  </form>
      </td>

  </tr>

</table>
[/code]


Thanks in advance sorry for so long code didnt know how to sammorzing it .
Link to comment
Share on other sites

Don't forget to remove your database connection info when posting.

I'd suggest calling each of the checkboxes the same thing, something like [color=green]todelete[][/color] but with the value of [code=php:0]$MASSEGES['id'][/code] this way you'll end up with an array called [color=green]$todelete[/color] in php and you can use it something like this:

[code]<?php
$delete = implode(",", $todelete); // This creates a string of id's e.g. "1,4,8,"
$limit = count($todelete); // set a limit as a safety precaution

$sql = "DELETE FROM tablename WHERE id IN ($delete) LIMIT $limit";
$result = mysql_query($sql);
if ($result){
  echo "The following ID's were successfully deleted: $delete\n";
}
else {
  echo "There was an error deleting rows from the database\n";
}
?>[/code]

Regards
Huggie
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.