I am submitting data from a form to a backend PHP file. The file is called settings.php and will not for some reason submit the data to the database. The database connection is working, and I've been trying to solve this for more than a day.
It did work before, but I decided to do some changes to the files and I must have messed something up, maybe I'm to blind to see it myself.
Here's the HTML part:
$infoSql = "SELECT * FROM info WHERE uname = '$username'";
$infoResult = mysqli_query($conn, $infoSql);
$infoRow = mysqli_fetch_assoc($infoResult);
$infoResultCheck = mysqli_num_rows($infoResult);
if($infoResultCheck == 0) {
echo ' <form action="includes/settings.php" method="post" enctype= multipart/form-data>
<div class="user_settings_beggining">
<div class="form_set_user_top">
<p>Beskriv dig själv</p>
</div>
Var bor du?
<input type="text" name="school" required>
<br>
Är du frisk?
<input type="text" name="class" required>
<br>
Din inställning till viruset
<input type="text" name="motto" required>
<br>
Profilbild:
<input type="file" name="picture">
<br>
Rensa:
<input type="reset" value="Rensa" style="align-self:
flex-start;
width: 100px;
background: none;
border: 1px solid black;
outline: none;
cursor: pointer;
padding: 5px;">
<br>
<input type="submit" value="Klar" style="align-self:
flex-start;
width: 100px;
background: none;
border: 1px solid black;
outline: none;
cursor: pointer;
padding: 5px;">
</div></form>
';
}
Here's the PHP code:
require "database.php";
session_start();
$username = $_SESSION["uname"];
$file = $_FILES["picture"];
$user_school = mysqli_real_escape_string($conn, $_POST["school"]);
$user_class = mysqli_real_escape_string($conn, $_POST["class"]);
$user_motto = mysqli_real_escape_string($conn, $_POST["motto"]);
$fileName = $_FILES["picture"]["name"];
$fileTmpName = $_FILES["picture"]["tmp_name"];
$fileSize = $_FILES["picture"]["size"];
$fileError = $_FILES["picture"]["error"];
$fileType = $_FILES["picture"]["type"];
$fileExt = explode(".", $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array("jpg", "jpeg", "png", "gif");
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = "../profile-img/".$fileNameNew;
if(isset($file)) {
if(in_array($fileActualExt, $allowed)) {
if($fileError === 0) {
if($fileSize < 5000000) {
move_uploaded_file($fileTmpName, $fileDestination);
}
}
}
} else {
$fileNameNew = 'null';
}
$sql = "INSERT INTO info (uname, user_image, user_school, user_class, user_motto)
VALUES ('$username', $fileNameNew', '$user_school', '$user_class, '$user_motto');";
mysqli_query($conn, $sql);
header("Location: ../user.php?success");