I have a contact form where a user fills it out and takes them to another page thanking them after they hit the submit button. I was wondering how to just have the thank you message appear on the same page (preferably right underneath the submit button) after they hit submit.

Here is my HTML:

<form id= "contact" form action="thankyou.php" method="post" class="basic-grey">
<h1>Contact Us
    <span> Fill out your comments or questions here!</span>
    <span>Your Name :</span>
    <input id="name" type="text" name="u_name" placeholder="Your Full Name" />

    <span>Your Email :</span>
    <input id="email" type="email" name="u_email" placeholder="Valid Email Address" />

    <span>Subject :</span>
    <input id="subject" type="subject" name="subj" placeholder="Subject"/>

    <span>Message :</span>
    <textarea id="message" name="message" placeholder="Your Message"></textarea>
    <input type="submit" class="button" value="Submit" /> 

Here is my php:

require 'connection.php';
$conn    = Connect();
$name    = $conn->real_escape_string($_POST['u_name']);
$email   = $conn->real_escape_string($_POST['u_email']);
$subj    = $conn->real_escape_string($_POST['subj']);
$message = $conn->real_escape_string($_POST['message']);
$query   = "INSERT into tb_cform (u_name,u_email,subj,message) VALUES('" .          $name . "','" . $email . "','" . $subj . "','" . $message . "')";
$success = $conn->query($query);

if (!$success) {
    die("Couldn't enter data: ".$conn->error);


 echo "<h2> Your inquiries have been received. You will get a reply as soon as         possible! </h2>";



1 Answer 1


The return value of a successful $mysqli->query involving INSERT is true (it does not return an object), so you can test for this and echo a corresponding message.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .