SieRobin Posted February 28, 2006 Share Posted February 28, 2006 I have two radio buttons made.Male | FemaleI want to be able to pass this over to another page, I've already posted the tags into the PHP code, but how do I configure PHP to knowing which button is selected? I want to put the selected button in the database, under "gender" of course. Could someone help me out?Thanks in advance :] Quote Link to comment https://forums.phpfreaks.com/topic/3732-radio-button/ Share on other sites More sharing options...
php_b34st Posted February 28, 2006 Share Posted February 28, 2006 I am assuming that you have already posted the data to the script that you want to parse the information and that you already know how to connect to your db? Use the following code to input the data into the db:i have used gender as the name of your radio button.[code]//post the data from your form$gender = $_POST['gender'];//insert into db$sql = "INSERT INTO your_db_name (gender) VALUES ('$gender')"; $result = mysql_query($sql);//you can check if the data has been inserted properlyif(!$result){ echo 'There was a problem inserting your data into the databse please try again later';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3732-radio-button/#findComment-13079 Share on other sites More sharing options...
soccer022483 Posted February 28, 2006 Share Posted February 28, 2006 Here is the form:[code]<form action="another_page.php" method="get"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="female" /> Female <input type="submit" name="submit" value="Go" /></form>[/code]When you click 'Go' on this form, it will take you to 'another_page.php'. On this page you need to make sure they arrived from that form by doing this:[code]if(isset($_GET['submit'])) { //I'll explain what goes here in a minute}else { //an error message here}[/code]Now, once we're in the if statement, we need to get the gender. (check the post before mine)[code]$gender = $_GET['gender'];//whatever you want to do with $gender here[/code]I have used GET instead of POST here. This way you can see the variables in the address bar in your browser. I like to use GETs until I have everything working right, then change everything to POST so the user doesn't see the variables. Quote Link to comment https://forums.phpfreaks.com/topic/3732-radio-button/#findComment-13082 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.