Jump to content

Recommended Posts

hy there i want to make a function that show the messages that are holded into an DB,everything nice,but when i try to delete the  message,it delete just one (the last record from DB)

near messages i do have a checkbox and checkbox have the name of message ID (uniq)

how can i make to delete everything that i want,it seem that it doesnt respect IF statement.

look at my function

 

function ShowMessages() {

global $db;

$msgcount1 = "SELECT * FROM `" . DBPREFIX . "users_messages` WHERE `ReciverID` = " . $db->qstr ( $_SESSION['user_id'] );
$msgcount = $db->RecordCount($msgcount1);

if ($msgcount == 0) {
echo '<center>No new message</center>';
} else if ($msgcount > 0) {
echo '
</td></tr>
<tr><td align="center" class="tdn" colspan=3><select class=input name="wn" size=1><option value="b">tagged messages<option value="a">all messages<option value="c">untagged messages</select>
<select name="to" size=1 class=input>
<option value="l">delete</select>
<input type=submit name="do" class=input value="Go!"></th></tr>
<input type=hidden name="o" value="0">';

$query = "SELECT * FROM `" . DBPREFIX . "users_messages` WHERE `ReciverID` = " . $db->qstr ( $_SESSION['user_id'] ) . " ORDER BY SendTime DESC LIMIT 0,50";
$query1 = mysql_query($query);
$message = $db->getRow ( $query );

while ($mess = mysql_fetch_array($query1)) {
if ($message->MessageType == 1) {
$sendername1 = "SELECT Username FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $mess['SenderID'] );
$sendername = $db->getRow ($sendername1);
$suid2 = $mess['ID'];
echo '
<tr>
<td class="tdn" valign="top">
<input type=checkbox name="',$mess['ID'],'" value="y">
</td>';
echo '
<td width="30%" class="tdn" valign="top">'.date("D, d.m.Y - H:i:s",$mess['SendTime']).'</td>';
echo'
<td class="tdn"><table width="100%">
<tr>
<td>message  <a href="player.php?p='.$mess['SenderID'].'">'.$sendername->Username.'</a> | Subject:'.$mess['Subject'].'</td>
<td align="right"><a class="copyright" href="msgbad.php?mn=9240519">(report)</a></td></tr>
<tr><td colspan=2><textarea cols=55 rows=4 class=input>'.$mess['Message'].'</textarea></td></tr><tr><td><a href="msgnew.php?st='.$sendername->Username.'">answer</a></td></tr></table><br></th></tr>
';


}
}
}

if($_POST['do'] == "Go!") {
if($_POST['wn'] == "b") {
if($_POST['to'] == "l") {
mysql_query("DELETE FROM `" . DBPREFIX . "users_messages` WHERE ReciverID = " . $_SESSION['user_id'] . " AND ID = " . $suid2 . "") or die(mysql_error());
}
} else if ($_POST['wn'] == "a") {
mysql_query("DELETE FROM `" . DBPREFIX . "users_messages` WHERE ReciverID =" . $_SESSION['user_id'] . "") or die(mysql_error());
} else if ($_POST['wn'] == "c") {
mysql_query("DELETE FROM`" . DBPREFIX . "users_messages`WHERE ReciverID = " . $_SESSION['user_id'] . " AND ID != " . $suid2 . "") or die(mysql_error());
}
}

echo '
<tr><td align="center" class="tdn" colspan=3><select class=input name="wn" size=1><option value="b">tagged messages<option value="a">all messages<option value="c">untagged messages</select>

<select name="to" size=1 class=input>
<option value="l">delete</select>
<input type=submit name="do" class=input value="Go!"></th></tr>
';
}

 

i did try various things on it,but it result in same thing  ???

anyone have a clue what can be?

thank you very much

Link to comment
https://forums.phpfreaks.com/topic/111455-php-and-mysql-delete-question/
Share on other sites

it seem that i have a very messy code.

can anyone please give a basic code that select something from DB - > echo it - >+ checkboxes

with 3 delete option

1 delete checked messages

2 delete all

3 delete unchecked

 

just a basic script please.i really dont know how i can do this one  ???

thanks again for your time

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.