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
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>

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.