samedi 22 octobre 2016

Simple checkboxes adding values together PHP

I'm coding something which should be rather simple but I can't get my head around it. I have a script which sells Cars a User has got from my game but in the garage they can press checkboxes to select certain cars to sell. I have this for my form to select checkboxes:


<input id="select_car" name="select_car['.$CarID.']" type="checkbox" value="'.$CarValue.'" onclick="CountCheck()" />


in the php side of it when the user hits sell selected I've got this:


'if (isset($_POST['sell_selected'])){

$PostValues = $_POST['select_car'];

foreach($PostValues as $value) {

        $CarStuff = $db->prepare("SELECT * FROM garage WHERE id = :id"); 
                                                $CarStuff->bindParam(":id", $value);
                                                $CarStuff->execute();
                                                $CarInfo = $CarStuff->fetchObject();

} }`


When I try to get any information from my object it says "Trying to get property of non-object". Not sure why?

On the other hand, how would I add the values together to get the total amount of money the cars selected are worth?

Thanks for any help given!




Aucun commentaire:

Enregistrer un commentaire