Delete client info using selectbox php and mysql

Monday, June 30, 2014

Alright here's what am trying to do.

I have a table which returns the list of information aside from the name of each 97 clients per row. Now am planning to do a delete section in one of the pages tab.

Here's how I call the values from the database to display it on the table:

<span class="text"><?php echo $fname; ?></span>
<span class="text"><?php echo $lname; ?></span>
<span class="text"><?php echo $bday; ?></span>

I placed it under an array. So each time a new addition has been placed, it will automatically be displayed too.

Now getting back to the main topic. As for the delete section, here's what am trying to do: Create a selectbox where it displays the Name of the client but the values fetched must be the ID.

So I interpreted the logic in this format:

<option value="<?php $id ?>"><?php $fname." ".$lname ?>
<option value="<?php $id ?>"><?php $bday ?>

What am trying to achieve here is once the user selects the name of the client he/she intends to delete, the system instead will get the value ID of the selected name then its details would be displayed on a textfields designated for each of the rows. Then once the button for delete (underneath these textfields) would prompt the question "Are you sure you want to delete from the record?" If the user clicks yes, then that selected name with that ID would be deleted from the DB.

That for me is quite tricky, since I didn't know if the way I call the $id on the option attribute for selectbox was even right? I just want to make it a referrence for the delete function like this:


sql="delete from clients where id='$selectedID' "

Anyone who once had to deal with this or has an idea on how to achieve this? Need your help.