kymo1970 Posted September 25, 2012 Share Posted September 25, 2012 I have a simple web form that I am having problems with have tried several different things and still can not get it to work right. I Have several radio buttons with numbers to choose from and when I choose one with a value that has more than one digit it does not take more than the first digit even though the address bar shows the correct value what do I have to do to get the full number to work with the program. Here is the code I have written for this. The first three buttons work and the code I had before I made the if statements would only use the first digit and return a one for 10, 12, and 100 and for the 20 it would return a one or a two. Now with the if statements the values with more than one digit do not return anything but the 4, 6, and 8 work fine. <form method="get" name="input" action="randomphp.php"><input type="radio" name="number" value="4" />4<input type="radio" name="number" value="6" />6<input type="radio" name="number" value="8" />8<input type="radio" name="number" value="10" />10<input type="radio" name="number" value="12" />12<input type="radio" name="number" value="20" />20<input type="radio" name="number" value="100" />100<br /><input value="Roll" type="submit" /></form><p id="random"></p><?php $ran=1; $ran = $_GET["number"]["value"]; if ($ran == "4") { $int = mt_rand(1,4); echo $int; } else if ($ran == "6") { $int = mt_rand(1,6); echo $int; } else if ($ran == "8") { $int = mt_rand(1,8); echo $int; } else if ($ran == "10") { $int = mt_rand(1,10); echo $int; } else if ($ran == "12") { $int = mt_rand(1,12); echo $int; } else if ($ran == "20") { $int = mt_rand(1,20); echo $int; } else if ($ran == "100") { $int = mt_rand(1,100); echo $int; } /*echo mt_rand(1,100);*/?> Link to comment Share on other sites More sharing options...
Ingolme Posted September 25, 2012 Share Posted September 25, 2012 I'm not sure what this is about: $_GET["number"]["value"]; You should be able to access the value with $_GET["number"]; alone. Your code could be much simpler: $ran = isset($_GET['number']) ? $_GET['number'] : 1;echo mt_rand(1, $ran); Link to comment Share on other sites More sharing options...
kymo1970 Posted September 28, 2012 Author Share Posted September 28, 2012 Thanks very much I started out trying to use ["value"] and when that did not work I added ["number"] in front and did not try it by itself works beautifully now thanks again :> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now