How to pass column data through form button?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toothpick
Forum Newbie
Posts: 2
Joined: Wed Feb 11, 2004 12:19 pm
Location: St. George, UT

How to pass column data through form button?

Post by toothpick »

Sorry for the possibly confusing subject, here's what I'm trying to do. I've made a form that uses this while loop to go through each row in a mysql table and displays the data in a table.

Code: Select all

while($row=mysql_fetch_array($query))
{

echo "
<td>$row&#1111;custNo]</td>
<td>$row&#1111;fName]</td>
<td>$row&#1111;lName]</td>
<td>$row&#1111;address]</td>
<td>$row&#1111;city]</td>
<td>$row&#1111;state]</td>
<td>$row&#1111;zip]</td>
<td>$row&#1111;phone]</td>
<td><FORM METHOD='post' ACTION='delete.php'>
<INPUT TYPE='SUBMIT' VALUE='Delete'></FORM></td>

</tr>";
&#125;
As you can see, each row has it's own Delete button (using Submit to go to delete.php). What I am trying to figure out, is how to send the ID(custNo in my example) that the row that the clicked Delete button is on to delete.php so I can display that row data and confirm the delete.

Thanks in advance for any help.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

you are useing a form, why not just add a hidden field with ID as the value? :?

Code: Select all

<input type="hidden" name="id" value="id_here">
toothpick
Forum Newbie
Posts: 2
Joined: Wed Feb 11, 2004 12:19 pm
Location: St. George, UT

Post by toothpick »

Good point, I had a bit of a brainfart there. I also found out this way to do it:

I replaced

Code: Select all

<td><FORM METHOD='post' ACTION='delete.php'>
with

Code: Select all

<td><FORM METHOD='post' ACTION='delete.php?id=".$row&#1111;'custNo']."'>
That gets it done. Thanks
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

hm..ur passing the id in GET, i dont see a need for the form there, you can pass it with a link too :P
Post Reply