Jump to content

Checkboxes


Cetanu

Recommended Posts

Okay, I am good with radio buttons and text boxes, but checkboxes are confusing me!

 

I basically have this.

 

1) Choose a Species -> 2) Depending on species switch options -> If species A is chosen give choices using checkboxes, but if B is chosen use radio buttons.

 

 

I have the radio buttons' data being stored in a database, but how do I make the checkbox values get stored if the person chooses A ?

For example, if they choose A and then check the first checkbox, how do I make that box's value get entered into a database?

 

I know it involves strings and arrays and stuff. This is my code:

<?php
if($row['species']=="Alien"){

echo "Aliens must choose a primary and secondary weapon considering they do not have technology available to them...<br/>";

echo "<input type='checkbox' name='AWeapon[]' value='Tail'/> The <strong>alien tail</strong> is a formidable weapon for anything a xenomorph is fighting. The tail 
gives the alien range, and it is razor sharp. <br/> 
<div style='color: red;'>+5 Attack</div> <br/> 

<input type='checkbox' name='AWeapon[]' value='Inner Jaws'/> The <strong>inner jaws</strong> of an alien are the trademark of the creature. They are a tongue-like protrusion 
that extends out of the mouth and can pierce metal.<br/> 
<div style='color: red;'>+5 Attack | -5 Defense | -5 Sneak </div><br/> 

<input type='checkbox' name='AWeapon[]' value='Claws'/> The <strong>claws</strong> of an alien can tear through metal, flesh, and bone. They are useful, but not always effective 
when sneaking about.<br/> 
<div style='color: red;'>+5 Attack | -5 Defense | -10 Sneak</div><br/>";
}
}
if($row['species']=="Predator"){ 
echo "Predators have a bunch of weapons available, but novice hunters cannot use all of these. Instead, you must choose weapon sets for your character.<br/>"; 
echo "<input type='radio' name='PWeapon' value='Ranged'/> The <strong>Ranged Weapon Set</strong> includes the netgun, speargun, and smart disc. It is 
good for those not willing to get their hands dirty, and that like to have the upper hand.<br/> 

<div style='color: red;'>+5 Attack | +5 Defense | -5 Honor</div><br/> 

<input type='radio' name='PWeapon' value='Melee'/> The <strong>Melee Weapon Set</strong> includes the wristblades, the spear, and the whip. It is 
for those who seek to be the best-of-the-best in close-combat, and for those who wish to maintain honor.<br/> 

<div style='color: red;'>+5 Attack | -5 Defense | +5 Honor</div><br/>"; 
} 
if($row['species']=="Marines"){ 
echo "The Marines are skilled with many weapons. They mostly use human weapons, which are weaker than Predator and Alien weaponry, yet they still get the 
job done! Please select a primary and a secondary weapon.<br/>";
echo "<input type='checkbox' name='MWeapons[]' value='Rifle'/> The <strong>M41 Pulse Rifle</strong> is standard for Marines. It is a ranged weapon, and can be 
upgraded with a grenade launcher.<br/> 
<input type='checkbox' name='MWeapons[]' value='Launcher'/> Outfit with Grenade Launcher for 100 pieces of money?<br/> 

<div style='color: red;'>+5 Attack | +5 Defense | -5 Melee</div> WITH GRENADE LAUNCHER:  
<div style='color: red;'>+10 Attack | +5 Defense | -10 Melee</div> <br/> 

<input type='checkbox' name='MWeapons[]' value='Flamethrower'/> The <strong>Flamethrower</strong> is good for mid-ranged targets, and can also provide 
extra defense until the flames die down.<br/>  
<div style='color: red;'>+5 Attack | +5 Defense | +5 Melee</div><br/> 

<input type='checkbox' name='MWeapons[]' value='Pistol'/> <strong>Standard Issue Pistols</strong> are not good for far targets, but they will pierce Alien
chitin. <br/> 
<div style='color: red;'>+5 Attack | -5 Defense | +5 Melee</div><br/>"; 
} 
echo "<input type='submit' value='Equip Character' name='equip'/>";
}
?>

 

The checkboxes have names like AWeapon[] so the arrays are easier  to make.

Link to comment
https://forums.phpfreaks.com/topic/171182-checkboxes/
Share on other sites

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.