I'm quite new to PHP and MySQL, and i desperately need some help. I've made a register page that connects to a db in MySQL, which has a foreign key for id in my donate db. So a user has to sign up before they can donate. But for some reason, I cannot figure out how to add the donations to the donate db. The form only has a donate amount value that the user can enter, and also a radio input where they can choose which animal they would like to donate to. So basically I need to add the donations to the donate db. Any help would be appreciated.
<?php
if(isset($_SESSION['userId'])){?>
<div class="col-sm-8">
<p><form name="form2" method="POST">
<div class="form-group">
<input type="text" name="value" class="form-control" id="value" placeholder="Donation amount*" required >
</div>
<div class="form-group">
Animal:</br></br>
<input type="radio" name="animal" value="panda"> Panda</br></br>
<input type="radio" name="animal" value="tiger"> Tiger</br></br>
<input type="radio" name="animal" value="elephant"> Elephant</br></br>
<input type="radio" name="animal" value="polarbear"> Polar Bear</br></br>
<input type="radio" name="animal" value="koala"> Koala</br></br>
</div>
</div>
<button type="submit" name="donate" class="btn btn-secondary">DONATE</button>
</form>
<?php
}
else{
what's here isn't important
this bit is important
} if(isset($_POST['donate'])){
$id = $_GET['userId'];
$value = $_POST['value'];
$animal = $_POST['animal'];
$stmt = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt, $sql)){
echo '<script>alert("SQL mistake.");</script>';
exit();
}
else{
if ($con->query($sql) === TRUE) {
$res = mysqli_query($con,"SELECT id FROM users WHERE id = 'id'");
while ($rows = mysqli_fetch_array($res)) {
$id = $rows['id'];
$sql = "INSERT INTO donate (value, animal, id) VALUE (?, ?, ?)";
}}}
I hope what I've written isn't too dumb, sorry if it is. But if anyone can help me with this, it would be appreciated. Thank you.