Jump to content

Recommended Posts

I am writing a code that displays the messages from a database and then has the option to delete a message.  Everything is working great except that I can only delete the first message in the list of messages every time.  Cant seem to figure this one guys..  any help would be appreciated.  Here is the code:

 

<font size="6" face="Arial"><b><center>Administration Area</center></b></font><br><br>
<!-- Start of FORM -->
<form method="POST" action="messages.php">
<center>
<table border="0"  width="90%">
  <tr><!-- Row 1 -->
     <td align="left"><input type="submit" value="Delete"></td><!-- Col 1 -->
     <td></td><!-- Col 2 -->
  </tr>
</table>
</center>
<center><table border="1" width="90%" style="border-bottom:none;border-left:none;border-right:none;border-top:none;">
                           <tr>
				   	   <td valign='top' align="center"  style="border-bottom:none;border-left:none;border-right:none;border-top:none;">Check</td><!-- Col 1 -->
				   	   <td valign='top'  style="border-bottom:none;border-left:none;border-right:none;border-top:none;">Date</td><!-- Col 1 -->
					   <td  style="border-bottom:none;border-left:none;border-right:none;border-top:none;">
					   Subject
                           </td></tr><!-- Col 1 -->

<?php
			  include('database.php');
                  $cxn = mysqli_connect($host,$user,$password,$dbname)
                  	      or die ("Couldn't connect to server");
                
                  $sql = "SELECT * FROM messages WHERE File='Inbox'";

                $result = mysqli_query($cxn,$sql);
                while($row = mysqli_fetch_row($result))
                {

                echo   "<tr>
				   	   <td valign='bottom' width='10%' align='center'><input type='checkbox' name='Delete' value='$row[0]'></td>";

			echo "</form><form method='POST' action='messages2.php'>";
					   
			echo   "<td valign='bottom' width='15%'>$row[4]</td><!-- Col 1 -->
					   <td valign='bottom' width='60%'>
						<input type='hidden' name='ID' value=".$row[0].">
                            <input type=submit value='".$row[2]."' style='background-color:transparent;border:none;font-family:arial;font-size:inherit;font-weight:bold;color:#FF0000;'> 
                           </td></tr><!-- Col 1 -->
					   ";
					   
			 echo "</form>";
			}

			print "</table></center>";

?>
</form>

 

Link to comment
https://forums.phpfreaks.com/topic/203324-message-coding-problem/
Share on other sites

Sorry about that, i thought I had put the full coding in but only got a part of it.  The full page coding is included.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <style type="text/css">
    a:link {text-decoration: none;}
    a:visited {text-decoration: none;}
  </style>
<?php

IF((isset($_POST['Delete'])) == TRUE)
{
  $Delete = $_POST['Delete'];
}
ELSE
{
$Delete = "";
}

include('database.php');
$cxn = mysqli_connect($host,$user,$password,$dbname)
        or die ("Couldn't connect to server");
$sql = "DELETE FROM messages WHERE ID='$Delete'";

$result = mysqli_query($cxn,$sql)
               or die("Couldn't execute query: ".mysqli_error($cxn));
  
?>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#FF0000" vlink="#FF0000" alink="#FFFFFF">
<div style="position:absolute;left:2%;top:5%;height:79%;width:16%;">
<center>
<font size="5" face="Arial"><b><u>Site Guide</u></b></font><br><br>
<font size="4" face="Arial"><a href="indexmain.php">Home</a></font><br><br>
<font size="4" face="Arial"><a href="messages.php">Messages</a></font><br><br>
<font size="4" face="Arial"><a href="orders.php">Order Requests</a></font><br><br>
<font size="4" face="Arial"><a href="girls.php">Edit The Girls</a></font><br><br>
<font size="4" face="Arial"><a href="guys.php">Edit The Guys</a></font><br><br>
<font size="4" face="Arial"><a href="puppies.php">Edit The Puppies</a></font><br><br>
<font size="4" face="Arial"><a href="about.php">Edit Our Story</a></font><br><br>
<font size="4" face="Arial"><a href="photos.php">Edit Photos</a></font><br><br>
</center>
</div>
<div style="position:absolute;left:18%;top:5%;height:45%;width:26%;">
<img src="../Graphics/bmm_Logo.jpg" width="100%" height="99%" alt="" border="1" align="" style="border-color:#FFFFFF;">
</div>
<div style="position:absolute;left:44%;top:5%;height:79%;width:55%;max-width:55%;">
<font size="6" face="Arial"><b><center>Administration Area</center></b></font><br><br>
<!-- Start of FORM -->
<form method="POST" action="messages.php">
<center>
<table border="0"  width="90%">
  <tr><!-- Row 1 -->
     <td align="left"><input type="submit" value="Delete"></td><!-- Col 1 -->
     <td></td><!-- Col 2 -->
  </tr>
</table>
</center>
<center><table border="1" width="90%" style="border-bottom:none;border-left:none;border-right:none;border-top:none;">
                           <tr>
				   	   <td valign='top' align="center"  style="border-bottom:none;border-left:none;border-right:none;border-top:none;">Check</td><!-- Col 1 -->
				   	   <td valign='top'  style="border-bottom:none;border-left:none;border-right:none;border-top:none;">Date</td><!-- Col 1 -->
					   <td  style="border-bottom:none;border-left:none;border-right:none;border-top:none;">
					   Subject
                           </td></tr><!-- Col 1 -->

<?php
			  include('database.php');
                  $cxn = mysqli_connect($host,$user,$password,$dbname)
                  	      or die ("Couldn't connect to server");
                
                  $sql = "SELECT * FROM messages WHERE File='Inbox'";

                $result = mysqli_query($cxn,$sql);
                while($row = mysqli_fetch_row($result))
                {

                echo   "<tr>
				   	   <td valign='bottom' width='10%' align='center'><input type='checkbox' name='Delete' value='$row[0]'></td>";

			echo "</form><form method='POST' action='messages2.php'>";
					   
			echo   "<td valign='bottom' width='15%'>$row[4]</td><!-- Col 1 -->
					   <td valign='bottom' width='60%'>
						<input type='hidden' name='ID' value=".$row[0].">
                            <input type=submit value='".$row[2]."' style='background-color:transparent;border:none;font-family:arial;font-size:inherit;font-weight:bold;color:#FF0000;'> 
                           </td></tr><!-- Col 1 -->
					   ";
					   
			 echo "</form>";
			}

			print "</table></center>";

?>
</form>
<!-- End of FORM -->
</div>
<div style="position:absolute;left:18%;top:51%;height:33%;width:26%;">
</div>
<div style="position:absolute;left:2%;top:85%;height:13%;width:98%;">
</div>
</body>
</html>


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.