I have a form that consists of 4 radio buttons, each radio button represents a different shape either cuboid, cone, cylinder or sphere, I also have a session variable for each of those shapes ( each one is set to 0), when a user selects a radio button and submits the form I want it to add 1 to whatever shape was selected here is my code
HTML
<form action="question2.php" method="post">
<input type="radio" name="ans" value="cuboid">
<input type="radio" name="ans" value="cone">
<input type="radio" name="ans" value="cylinder">
<input type="radio" name="ans" value="sphere">
<input type="submit" value="Submit">
</form>
PHP
<?php
if(isset($_POST['submit'])) {
if(isset( $_POST['ans'])) {
$selected_answer = $_POST['ans'];
if($selected_answer == "cuboid") {
$_SESSION["cuboid"] = ((int)Session["cuboid"]) + 1;
}
}
}
?>
However this is not working. $_SESSION["cuboid"] just stays 0. Can anyone tell me where I am going wrong?
EDIT - I am defining the Session variable in a previous page like this
$_SESSION["cuboid"] = 0;
And also I have the following at the top of all my pages
<?php
session_start();
?>