I'm trying to insert the user and cursus id in the database on submit the current user is defined in the second part(see comment) and connection with the database is made in the require once on top of the file. When i press the button now its echoing success but in the database noting is showing up. Console is not showing up anything and when i echo $a or &b its giving me the correct id's. What is it that im doing wrong?
<?php
session_start();
require_once('includes/mysql_config.php');
//getting user data/id
$id = isset($_SESSION['id']) ? $_SESSION['id'] : header('location: login.php');
$result = mysqli_query($con, "SELECT * FROM users WHERE id =".$_SESSION['id']);
$user = mysqli_fetch_array($result);
require_once('header.php');
$id = $_GET['id'];
$result = mysqli_query($con, "SELECT * FROM cursus c LEFT OUTER JOIN cursussoort cr ON (c.cursussoort_ID = cr.id) WHERE c.ID = $id ORDER BY c.begindatum ASC");
$amount = mysqli_affected_rows($con);
for ($i = 0; $i < $amount; $i++) {
$cursus = mysqli_fetch_array($result);
$a = $cursus['id'];
$b = $user['id'];
//$a = mysqli_real_escape_string($a);
//$b = mysqli_real_escape_string($b);
if(isset($_POST['submit'])){
if($user['id']) {
$sql = "INSERT INTO aanmeldingen (users_id, cursus_id) VALUES ('$b', '$a')";
$result = mysqli_query($sql);
echo "success";
} else {
echo "failed";
}
}
?>
<div class="main-nav">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- <a class="navbar-brand" href="index.html">
<h1><img class="img-responsive" src="images/logo.png" alt="logo"></h1>
</a> -->
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="scroll active"><a href="index.php#home">Home</a></li>
<li class="scroll"><a href="index.php#services">Over ons</a></li>
<li class="scroll"><a href="index.php#pricing">Cursussen</a></li>
<li class="scroll"><a href="index.php#contact">Contact</a></li>
<?php if(isset($_SESSION['id'])) {
echo '<li><a href="myaccount.php"><span>Mijn account</span></a></li>';
echo '<li><a href="logout.php"><span>Log Out</span></a></li>';
} else {
echo '<li><a href="login.php"><span>Log In</span></a></li>';
} ?>
</ul>
</div>
</div>
</div><!--/#main-nav-->
<br><br>
<!-- Post Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<h1> <?php echo $cursus['naam_cursus'] . "<br />";?></h1>
van: <?php echo $cursus['begindatum'] . "<br />";?>
tot: <?php echo $cursus['begindatum'] . "<br />";?>
<?php echo $cursus['beschrijving'] . "<br />";?>
</div>
</div>
</div>
<form method="post">
<input type="submit" name="submit">
</form>
</div>
</div>
<?php } ?>
<hr>
If you guys need more information tell me.