0

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>
</h1>
<label>
    <span>Your Name :</span>
    <input id="name" type="text" name="u_name" placeholder="Your Full Name" />
</label>

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

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

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

Here is my php:

<?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>";

$conn->close();

?>

1 Answer 1

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 .