Jump to content

[SOLVED] Is it possible to do this (radio button holding array as value)


play_

Recommended Posts

<?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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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'];
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.