Hey guys!
I have managed to insert messages into my database and I thought that the insert query should allow the same user to insert multiple queries but it doesn’t allow me to do that… Here is my code:
<?php
session_start();
include_once 'includes/dbh.php';
if (!isset ($_SESSION['u_uid'])) {
header("Location: index.php?contactform=notlogin");
exit();
} else {
if (isset($_POST['ticket'])) {
header("Location: ticket.php");
exit();
}
if (!isset($_POST['submit'])) {
header("Location: index.php?contactform=error");
exit();
} else {
$ticket = 'qqewreqreqwsdfdfdafcbvcQERFGHFGHGFHRETERTDF!@#$%^^()';
$ticket = str_shuffle($ticket);
$ticket = substr($ticket, 0, 10);
$user_uid = $_POST['user_uid'];
$first = $_POST['first'];
$last = $_POST['last'];
$mailfrom = $_POST['mail'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$response = 'None';
$datesubmitted = date('Y-m-d H:i:s');
$datereplied = 0;
$solved = 0;
$mailTo = "piano0011@hotmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$firstname." ".$lastname.".\n\n".$message.".\n\n Thank you";
mail($mailTo, $subject, $txt, $headers);
$sql = "INSERT INTO customers_enquiry (user_uid, ticket, first_name, last_name, subject, mailfrom, message, response, datesubmitted, datereplied, solved) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
//Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo 'SQL statement failed';
} else {
//Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, "ssssssssssi", $user_uid, $ticket, $first, $last, $subject, $mailfrom, $message, $response, $datesubmitted, $datereplied, $solved);
//Run parameters inside database
mysqli_stmt_execute($stmt);
header("Location: index.php?contactform=success");
exit();
}
}
}