Jump to content

not returning correct result


stephenkusz

Recommended Posts

Hi all,

I need to have my results listed in a table (which is happening fine).

I then want to click on the delete icon next to a row to choose to delete that particular row (atm I am just trying to get the correct info to echo on results page).

The problem is, when I click the delete icon next to the row to delete (echo), it is always only returning the last row in the table, not the one I am choosing.

Hoping someone can help with this. Like I said, I'm just trying to echo the correct row atm, the actual delete part I'll look after once I get this working.

 

Here is the form:

 

<?php
include("memdb.php");
include("memtop.php");
$login = $_COOKIE['ID_my_site']; 
?>

<form name="filedelete" method="post" action="memfiledel.php">
<table class="tablesorter" id="files">
<thead>
<tr>
<th width="425">File Name</th>
<th width="50">Date</th>
<th width="25" background="/images/headblank.png" align="center">Delete</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT id,filename,date FROM testimonials WHERE login = '$login'";
$result=mysql_query($sql);
while($files=mysql_fetch_array($result)){
?>
	<tr>
	<input type="hidden" name="id" id="id" value="<?php echo $files['id']; ?>">
	<input type="hidden" name="filename" id="filename" value="<?php echo $files['filename']; ?>">
	<input type="hidden" name="date" id="date" value="<?php echo $files['date']; ?>">
	<td align="left"><a href="upload/<?php echo $files['filename']; ?>" target="_blank"><?php echo $files['filename']; ?></a></td>
	<td align="left"><?php echo $files['date']; ?></td>
	<td align="center"><input type="image" src="/images/delete.gif" border="0" onclick="return confirm('Are you sure you want to delete <?php echo $files['filename']; ?> ?')"></td>
	</tr>
        <?php } ?> 
  </tbody>
</table>
</form>

 

 

 

Here is the memfiledel.php file

 

<?php 
include("memdb.php");
include("memtop.php");

$login = $_COOKIE['ID_my_site']; 

$filename = $_POST['filename'];
$id = $_POST['id'];
$date = $_POST['date'];

echo "$id $filename $date";

?> 

 

Link to comment
https://forums.phpfreaks.com/topic/264493-not-returning-correct-result/
Share on other sites

Fixed, thank you so much gristoi. Can't believe how easy that was. Was stuck on this for days.

Now let's see if I can get it to actually delete the right one, I'm sure it will be fine now.

Again, thanks gristoi, I appreciate your help.

 

 

Here's what I changed.

 

 

<table class="tablesorter" id="files">
<thead>
<tr>
<th width="425">File Name</th>
<th width="50">Date</th>
<th width="25" background="/images/headblank.png" align="center">Delete</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT id,filename,date FROM testimonials WHERE login = '$login'";
$result=mysql_query($sql);
while($files=mysql_fetch_array($result)){
?>
	<tr>
	<form name="filedelete" method="post" action="memfiledel.php">
	<input type="hidden" name="id" id="id" value="<?php echo $files['id']; ?>">
	<input type="hidden" name="filename" id="filename" value="<?php echo $files['filename']; ?>">
	<input type="hidden" name="date" id="date" value="<?php echo $files['date']; ?>">
	<td align="left"><a href="upload/<?php echo $files['filename']; ?>" target="_blank"><?php echo $files['filename']; ?></a></td>
	<td align="left"><?php echo $files['date']; ?></td>
	<td align="center"><input type="image" src="/images/delete.gif" border="0" onclick="return confirm('Are you sure you want to delete <?php echo $files['filename']; ?> ?')"></td>
	</form>
	</tr>
        <?php } ?> 
  </tbody>
</table>

Archived

This topic is now archived and is closed to further replies.

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