Home >>MySQL Tutorial >How to edit radio button in PHP MySQL
//create a database CREATE DATABASE `demo`; //select database USE demo; //Create table CREATE TABLE `demo`.`update_radio_button_value` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` CHAR( 50 ) NOT NULL , `email` VARCHAR( 50 ) NOT NULL , `mobile` BIGINT NOT NULL , `gender` ENUM( "m", "f" ) NOT NULL ); //Insert Values INSERT INTO `demo`.`update_radio_button_value` ( `id` ,`name` ,`email` ,`mobile` ,`gender` ) VALUES (NULL , 'Sanjeev', 'Sanjeev@gmail.com', '9015501897', 'm');
<?php $connect= new mysqli("localhost","root","","demo") or die("ERROR:could not connect to the database!!!"); //select users data $query=$connect->query("select * from update_radio_button_value"); //fetch data $result=$query->fetch_array(); ?> <style> input{width:250px} input[type=submit]{width:120px; height:25px} table{padding:5px} </style> <form method="post" action="update.php"> <table style="background:#F8F8F8" border="0" align="center"> <tr> <td height="35">Name</td> <td><input type="text" name="n" value="<?php echo $result['name'];?>" /></td> </tr> <tr> <td width="58" height="40">Email</td> <td width="256"><input readonly="readonly" type="email" name="eid" value="<?php echo $result['email'];?>" /></td> </tr> <tr> <td height="42">Mobile</td> <td><input type="number" name="mob" value="<?php echo $result['mobile'];?>" /></td> </tr> <tr> <td height="70">Gender</td> <td> Male <input type="radio" name="gen" value="m" <?php if($result['gender']=="m"){ echo "checked";}?>/> <BR/> Female <input type="radio" name="gen" value="f" <?php if($result['gender']=="f"){ echo "checked";}?>/> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Update My Profile" name="update"/> </td> </tr> </table> </form>
<?php $connect= new mysqli("localhost","root","","demo") or die("ERROR:could not connect to the database!!!"); extract($_POST); if(isset($update)) { $query=$connect->query("update update_radio_button_value SET name='$n',mobile='$mob',gender='$gen' where email='$eid'"); if($query) { header('location:get_radio_button_checked_value.php'); } } ?>