<!DOCTYPE html>
<html lang="en">
<head>
<!-- head data stats here -->
<?php
include '../include files/head.php';
?>
<!-- head data ends here -->
</head>
<body>
<div class=" container">
<?php
if(isset($_POST["submit"])){
$image =$_POST["image"];
$title =$_POST["title"];
$errors = array();
if(empty($image) OR empty($title) ){
array_push($errors,"all fileds are required");
}
require_once "../config file/config.php";
// Check if title already exists
$sql = "SELECT * FROM genres WHERE title = '$title'";
$result = mysqli_query($conn, $sql);
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0) {
array_push($errors, "title already exists");
}
if(count($errors)> 0){
foreach($errors as $error){
echo"<div class='alert alert-danger' role='alert'>$error</div>";
}
}else{
$sql ="INSERT INTO genres (image,title) VALUES (?,?)";
$stmt =mysqli_stmt_init($conn);
$preparestmt = mysqli_stmt_prepare($stmt,$sql);
if ($preparestmt){
mysqli_stmt_bind_param($stmt,"ss", $image,$title);
mysqli_stmt_execute($stmt);
echo " <div class='alert alert-danger' role='alert'> title and images successfully </div>";
} else{
die("something went wrong");
}
}
mysqli_close($conn);
}
?>
<form action="genres.php" method="post">
<div class="form-group">
<label for="text"> enter titile </label>
<input type="text" class="form-control" name="title" placeholder="title">
</div>
<div class="form-group">
<label for="image">Select Image:</label>
<input type="file" class="form-control-file" name="image" id="image">
</div>
<div class="form-btn">
<input type="submit" class="btn btn-primary" value="submit"name="submit">
</div>
</form>
</div>
<!-- head data stats here -->
<?php
include '../include files/body.php';
?>
<!-- head data ends here -->
</body>
</html>
the error
database connection sucessful
Fatal error: Uncaught Error: mysqli object is already closed in G:xampphtdocsre zerobackend uploadinggenres.php:25
Stack trace:
#0 G:xampphtdocsre zerobackend uploadinggenres.php(25): mysqli_query(Object(mysqli), 'SELECT * FROM g...')
#1 {main} thrown in G:xampphtdocsre zerobackend uploadinggenres.php on line 25
as soon as i click on submit i get this error so idk why im getting this i tried everything i could to do it on how to fix the error like did i place some brackets at wrong place or something idk like no logic is working in it so im confused aff
i try everything i could to fix the issue and the code purpose is to submit that data to my xampp server which it is not doing
<?php
$hostname = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbname = "re-zero";
$conn = mysqli_connect($hostname, $dbuser, $dbpassword, $dbname);
if (!$conn) {
die("something went wrong," . mysqli_connect_error());
} else{
echo"database connection sucessful";
}
mysqli_close($conn);
?>