i try to create a little login+survey and try to write all data to a database. Especially it is important, to get a session id for each user in order to add information of each page of the survey to the right line of the database.
My problem is here, that it seems that the session is either not started or i can not create a session id. Writing in the database already works, but not if i include the lines about the session.
After google'ing a lot that always took me to the same answer (which is not working for me) i try it here. Here is my code, first the callDatabase.php is called, in this file a session id is created and the database entry is made (idk if this is the best solution though, i guess not xD):
<script type="text/javascript">
$.post( 'callDatabase.php', { 'entry[]': ["init"]} );
</script>
callDatabase.php:
<?php
header('Content-Type: text/json');
$test = $_POST['entry'];
session_start();
$sID = session_id();
$timestamp = time();
$servername = "local";
$username = "root";
$password = "rootpw";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysqli_select_db($conn, 'myDb');
$sql = "INSERT INTO myTable (sID, timestamp, t1, rating, start, end, color, fight, completed)
VALUES ('$sID', '$timestamp', '-', '4', '_', '_', '_', '_', 'false')";
mysqli_query($conn, $sql);
mysqli_close($conn);
session_unset();
session_destroy();
$_SESSION = array();
?>
Like i said, without the session stuff, it is working fine, with it, the browser is running forever and i get no entry in my database. Since i get no error message i did not find any solution about how to fix it. It is running locally, with XAMPP and a mysql database.