PHP Classes

File: contact-us-php/submit_contact.php

Recommend this page to a friend!
  Packages of ganesh kavhar   Contact Us Page With Database in PHP   contact-us-php/submit_contact.php   Download  
File: contact-us-php/submit_contact.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Contact Us Page With Database in PHP
Show and process a contact form using a database
Author: By
Last change:
Date: 8 months ago
Size: 602 bytes
 

Contents

Class file image Download
<?php
include 'includes/db.php';

$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
$message = $_POST['message'] ?? '';

if (
$name && $email && $message) {
   
$stmt = $conn->prepare("INSERT INTO messages (name, email, message) VALUES (?, ?, ?)");
   
$stmt->bind_param("sss", $name, $email, $message);

    if (
$stmt->execute()) {
        echo
"Thank you for your message!";
    } else {
        echo
"Something went wrong. Please try again.";
    }

   
$stmt->close();
} else {
    echo
"All fields are required.";
}

$conn->close();
?>
<br><a href="contact.php">Back to Contact Form</a>