getting information from radio buttons in php

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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

getting information from radio buttons in php

Post by nigma »

I am trying to make a script that I can access online that will allow me to delete data from a MySQL database. I wanna make it using radio buttons. I have already got a php script that will print a radio button and then the all the data in that row. But I dont know how to tell which radio button was selected. Anyone know how to do this?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Code: Select all

<?php
  if (!empty($_POST['update'])) {
   switch ($_POST['myradio']) {
     case 'myval1':
        # do something
        break;
     case 'myval2':
        # do something else
        break;
     default:
        # give some error message (invalid data)
   }
  }
?>
<form action="myfile.php" method="post">
<input type="hidden" name="update" value="1">
Please select<br>
<input type="radio" name="myradio" value="myval1"> My value 1<br>
<input type="radio" name="myradio" value="myval2"> My value 2<br>
<input type="submit" name="submit" value="Submit">
</form>

?>
Post Reply