<?php
$con=mysqli_connect("host","user","pwd","db") or die("Connection failed:" .mysqli_connect_error());
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["submit"])) {
$name = $_POST["name"];
$hidename = $_POST["hidename"];
$title = $_POST["title"];
$confession = $_POST["confession"];
$comments = $_POST["comments"];
$email1 = $_POST["email1"];
$email2 = $_POST["email2"];
$email3 = $_POST["email3"];
$email4 = $_POST["email4"];
$email5 = $_POST["email5"];
$sql = "INSERT INTO confessions (username,title,confession,hidename,comments,email1,email2,email3,email4,email5) VALUES ('$name', '$title', '$confession', '$hidename', '$comments', '$email1' ,'$email2', '$email3', '$email4', '$email5')";
mysqli_query($con, $sql);
echo("Confession saved");
}
?>
I want to insert these inputs into a database in phpadmin. This code worked once, and then it stopped working for a few hours. I edited the code made many changes, and again, it worked once and it stopped working. I edited the code all over again, and for the third time, it worked for once, and it stopped working, I am using Dreamhost servers which use PHP 8.1 FastCGI to build this website. It worked once and stopped working for a few hours three times, and all three times, it was different code. I don’t know what I am doing wrong.
I tried changing the code three times using YouTube tutorials. I’ve also tried closing the connection, but it did not work.