play_ Posted February 15, 2007 Share Posted February 15, 2007 <?php $info = array('health' => 4); ?> <form action="#" method="post"> Char1<br /> <input type="radio" value="<?php echo $info ?>" name="char" /><br /> <input type="submit" name="submit" /> </form> <?php if(isset($_POST['submit'])) { echo $_POST['char']; } ?> That doesn't work. if i do: <input type="radio" value="<?php echo $info ?>" name="char" /> i get an offset error. Not possible is it? Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 you need to use echo $info['health'] Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 15, 2007 Share Posted February 15, 2007 Not sure what you're trying to do. You want a radio button to hold a value? Or are you trying to figure out a way to automatically select which radio button is chosen? Your example has one radio button. Radio's are an 'either/or' choice selection. Please clarify your question Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 Your code should be: <?php $info = array('health' => 4); ?> <form action="#" method="post"> Char1<br /> <input type="radio" value="<?php echo $info['health'] ?>" name="char" /><br /> <input type="submit" name="submit" /> </form> <?php if(isset($_POST['submit'])) { echo $_POST['char']; } ?> Quote Link to comment Share on other sites More sharing options...
play_ Posted February 15, 2007 Author Share Posted February 15, 2007 Your code should be: <?php $info = array('health' => 4); ?> <form action="#" method="post"> Char1<br /> <input type="radio" value="<?php echo $info['health'] ?>" name="char" /><br /> <input type="submit" name="submit" /> </form> <?php if(isset($_POST['submit'])) { echo $_POST['char']; } ?> Thanks. However this was just an exmaple. The array actually holds more value, such as strength, weapon, etc. Which i will be later store in the database Quote Link to comment Share on other sites More sharing options...
papaface Posted February 15, 2007 Share Posted February 15, 2007 You never mentioned that it was just an example. Tell us exactly what you want, we cant help unless you provide us with the proper information. Quote Link to comment Share on other sites More sharing options...
play_ Posted February 15, 2007 Author Share Posted February 15, 2007 Not sure what you're trying to do. You want a radio button to hold a value? Or are you trying to figure out a way to automatically select which radio button is chosen? Your example has one radio button. Radio's are an 'either/or' choice selection. Please clarify your question Here's the situation, in case there's a better solution. I have register.php where users sign up. They enter: -name -email -password Then, i have a query. The query retrieves the following information from a table called 'characters_list' and lists them: -characters_list_ID -character_race -initial_health -initial_strength -initial_weapon -character_image And next to each character, there's a radiobutton so the user can select a character to use. But when the user selects a character, i need to store initial_health, initial_strength, initial_weapon, etc in a table in the database. One alternative would be this: After the user enters his name, email and password, they could click a submit button which would store that info in the 'users' table, and then be taken to another page, say, character_select.php where they could select a character. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 Are you trying to let them select between multiple characters? Each one should have a unique ID, and you'd use the ID as the value. Quote Link to comment Share on other sites More sharing options...
play_ Posted February 15, 2007 Author Share Posted February 15, 2007 here the image of the register screen: http://img.photobucket.com/albums/v425/play/help/phpfreaks.jpg See how each character have their own initial_health, initial_strength and initial_weapon. When the user clicks submit, i need to take those 3 values and insert them somewhere else. ::edit:: I'll have them taken to a second page. Thanks all. 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.