Page 1 of 1

getting information from radio buttons in php

Posted: Sun Jan 26, 2003 12:28 pm
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?

Posted: Sun Jan 26, 2003 3:24 pm
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>

?>