I think this belongs here, but my $_POST won't grab the gender that was submitted through a form.
I am using AJAX so the page doesn't have to reload so it can go in a smooth transition, but the AJAX is grabbing the value perfectly fine.
I have a feeling the $_POST isn't grabbing the value because the page isn't reloading.. but I don't want to reload it.
These codes are all on the same page.
Here is my Javascript:
<script>
function chooseGender()
{
var gender = $('input[name=gender]:checked', '#submitgender').val();
if(gender)
{
$.ajax(
{
type: "POST",
url: window.location.pathname,
data: "gender=" +gender,
success: function()
{
alert("You have chosen to be a " + gender); //It's grabbing it perfectly fine!
$("#submitgender").hide(); //It hides the gender table so they can't choose a gender since they already have chosen one.
$("#rest").fadeIn(); //Shows the other table that's labeled "rest" as it's ID so they can choose what base, eyes, etc for that specific gender they've chosen.
}
});
}
else
{
alert('Select a gender.');
}
}
</script>
But here is the PHP inside the #rest table:
<?php
$gender = $_POST['gender'];
$sql = "SELECT * FROM habases WHERE gender='".$gender."'";
$result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn));
print_r($sql);
while ($row = mysqli_fetch_assoc($result))
{
$baseimage = $row['image'];
$baseskin = $row['skin'];
echo "<img src=\"http://www.elvonica.com/".$baseimage."\" value=\"".$baseskin."\">";
}
?>
And this is what I'm getting for the print_r:
SELECT * FROM habases WHERE gender=''