shirvo Posted February 8, 2007 Share Posted February 8, 2007 I want to know how i can get the data from radio buttons when they all are named the same. Quote Link to comment Share on other sites More sharing options...
fert Posted February 8, 2007 Share Posted February 8, 2007 $_POST['name'] or $_GET['name'] Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 If they are all named the same it won't work unless they're named something like button[] <-- you need the []. That will make the posted var an array; Quote Link to comment Share on other sites More sharing options...
shirvo Posted February 11, 2007 Author Share Posted February 11, 2007 <tr><td colspan="2"><input type="radio" name="V1[2]">Save my username</td></tr> Thats what i have but it dont work. The reason you have to have radio buttons with the same name is to make it that only one of them can be selected. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 11, 2007 Share Posted February 11, 2007 Heres an easy emaple of how the array works ok. <?php $a[]="Save my name"; $a[]="Save my username"; $a[]="Save my age"; $a[]="Save my address"; $save_array=array("my name","my username","my age","my address"); foreach ($save_array as $result1){ foreach($a as $result2){ $result=$result1.$result2; echo "you have selected $result to be saved <br>"; } } ?> Quote Link to comment Share on other sites More sharing options...
shirvo Posted February 11, 2007 Author Share Posted February 11, 2007 that didn't help. this is what i have <html><head> </head><body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr><td>Username:</td><td><input type="text" name="user" maxlength="40" value="<? echo $_COOKIE['username']; ?>"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="40" value="<? echo $_COOKIE['password']; ?>"></td></tr> <tr><td colspan="2"><input type="radio" name="V1[1]">Save my username and password</td></tr> <tr><td colspan="2"><input type="radio" name="V1[2]">Save my username</td></tr> <tr><td colspan="2"><input type="radio" name="V1[3]">Ask for my username and password</td></tr> <tr><td colspan="2"><input type="submit" value="Login" name="login"></td></tr> </table> </form> </body></html> so what am i meant to put in the name for each radio button Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 11, 2007 Share Posted February 11, 2007 <html><head> </head><body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr><td>Username:</td><td><input type="text" name="user" maxlength="40" value="<? echo $_COOKIE['username']; ?>"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="40" value="<? echo $_COOKIE['password']; ?>"></td></tr> <tr><td colspan="2"><input type="radio" name="V1[]">Save my username and password</td></tr> <tr><td colspan="2"><input type="radio" name="V1[]">Save my username</td></tr> <tr><td colspan="2"><input type="radio" name="V1[]">Ask for my username and password</td></tr> <tr><td colspan="2"><input type="submit" value="Login" name="login"></td></tr> </table> </form> </body></html> now look at my example agin ok. Quote Link to comment Share on other sites More sharing options...
shirvo Posted February 11, 2007 Author Share Posted February 11, 2007 but in the php when i use post eg $_POST['V1[]']; what do i do to find out which one of them was selected Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 11, 2007 Share Posted February 11, 2007 The only way i could work this out is to get all that have nothink in the varable and then update the database. <?php foreach ($v1 as $result){ if($result=="none"){ }else{ //do the update } } ?> Quote Link to comment Share on other sites More sharing options...
shirvo Posted February 11, 2007 Author Share Posted February 11, 2007 how does that tell me which radio button was selected. If you come up with an answer thats kool but i'm going to just not do the save username and password stuff. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 11, 2007 Share Posted February 11, 2007 why dont you do a real login system instead of all this trouble just ask the user if they want to join. as what i can tell from what your doing it is a registartion form but the hard way round. Quote Link to comment Share on other sites More sharing options...
shirvo Posted February 11, 2007 Author Share Posted February 11, 2007 because i was trying to have it easyer for the user of the website. It is for my family and i know what they are like and they would like it easyer Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 11, 2007 Share Posted February 11, 2007 <html><head> </head><body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr><td>Username:</td><td><input type="text" name="user" maxlength="40" value="<? echo $_COOKIE['username']; ?>"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="40" value="<? echo $_COOKIE['password']; ?>"></td></tr> <tr><td colspan="2"><input type="radio" name="V1[]" value="yes">NAME</td></tr> <tr><td colspan="2"><input type="radio" name="V1[]" value="yes">PASSWORD</td></tr> <tr><td colspan="2"><input type="submit" value="Login" name="login"></td></tr> </table> </form> </body></html> This might work if the user selected name AND PASSWORD then update the database or otherwise dont. <?php foreach($V1 as $x){ if(($x=="yes"){ //update database }else{ echo " You must select username and password to register"; } } ?> Quote Link to comment 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.