This question already has an answer here:
I am trying to make a reservation system, but everytime I try to submit, I get this error "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in", but the data still gets inserted to the database. It should also go to the submitted.php page, but it doesn't, it stays at the current page, I haven no idea what to do. Help me out guys, kinda new to PHP.
<?php
session_start();
include("connect.php");
include("functies.php");
$db = mysqli_connect($host, $user, $password, $db)
or die(mysqli_connect_error());
//when submit button is clicked
if(isset($_POST['submit'])) {
$artist = $_POST['Artist'];
$track = $_POST['Track'];
$trackDL = $_POST['DownloadLink'];
$genre = $_POST['Genre'];
$sml = $_POST['Links'];
$date = $_POST['releaseDate'];
$query = "INSERT INTO submissions (users_Id, artist, track, trackDL, genre, socialMediaLinks, dateRelease)
VALUES (" . $_SESSION['id'] . ", '$artist', '$track', '$trackDL', '$genre', '$sml', '$date' )";
$result = $db->query($query) or die(mysqli_connect_error());
if ($row = mysqli_fetch_array($result)) {
$sid = $row['submitId'];
$_SESSION['submitted'] = true;
$_SESSION['submitId'] = $sid;
}
}
mysqli_close($db);
submitted();
?>
This is my submitted function. When everything goes fine, it should go to the submitted.php file, but it doesn't.
function submitted(){
if (isset($_SESSION['submitted']) && $_SESSION['submitted'] == true) {
header("Location:submitted.php");
exit();
}
}
</div>