stephenkusz Posted June 20, 2012 Share Posted June 20, 2012 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"; ?> Quote Link to comment Share on other sites More sharing options...
gristoi Posted June 20, 2012 Share Posted June 20, 2012 you are creating your form in a loop, so every name for the hidden fields in the completed form is identical, thus the last IDENTICAL name is being passed through the post. Quote Link to comment Share on other sites More sharing options...
stephenkusz Posted June 20, 2012 Author Share Posted June 20, 2012 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.