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?

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

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

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

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.

 

 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.