How to create a ticket system

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();
    }

  }
 }

There is only one query there. Where is the second query you’re talking about?

Also, we’ve already told you about the mysqli_error function a few times. Have you tried that?

Maybe my logic here is not right with the ticket system but I want to make it in such a way that one user can post multiple questions… So that is why I thought a single query like this would be enough?

Multiple questions

Single query

Do you see the problem here?

1 Like

so I think I would need to do check for num rows to see if the record exists?

Why would a new question already exist?

What happens when you call this the second time, with the same user-id? You haven’t set the “user_uid” column to be unique, have you?

Use PDO and this lightweight MVC framework! You can create some epic lightweight scripts and I built a simple support ticket system using this framework in 1 hour so i suggest you take a look at it!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.