so im trying to store values from a checkbox into my database It works if I use a normal Textbox but as soon as I attempt it with a checkbox it doesnt work any idea? I want to have two for example checkbox1 and checkbox2 there values should be stored in my database colums for example Colum1 colum2. Thanks in advance for anyhelp
<form name="checkbox.php" id="names" action="<?php echo JURI::current(); ?>" method="post"> <p><input type="checkbox" name="game" value="ExampleGame" />b</p> <p><input type="checkbox" name="Age" value="ExampleAge" />b</p> <p><input id="submit" name="submit" type="submit" value="Submit Names" /></p> </form> <? if( (isset($_POST['game'])) || (isset($_POST['Age'])) ) { //first name or last name set, continue--> $game = $_POST['game']; $Age= $_POST['Age']; $db =& JFactory::getDBO(); $query = "INSERT INTO `gameTable` (`game`, `Age`) VALUES ($game, $age);"; $db->setQuery( $query ); $db->query(); } else { echo '<h4>One Field Is Required!</h4>'; } ?>
Advertisement
Answer
Try this
$query = "INSERT INTO `gameTable` (`game`, `Age`) VALUES ('".$game."','".$age."', )";