Reputation: 1
The code below is able to insert into the database but doesn't display anything.
I tried playing around with the code using JavaScript and AJAX though I only have basic understanding of the two and wasn't able to change anything.
I am a beginner and any help will be appreciated.
<?php
require_once 'connect.php';
if (isset($_POST['submit']))
{
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$sql = "INSERT INTO message (Names, Email, Numbers,Message)
VALUES ('$name','$email','$phone','$message')";
echo"Record Enterd";
if ($conn->query($sql) === true) {
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
?>
Upvotes: 0
Views: 5042
Reputation: 257
Try This:
echo "<script>alert('Record Added Successfully')</script>";
Upvotes: 2
Reputation: 5544
Use this
if ($conn->query($sql) === true) {
?>
<script type="text/javascript"> alert('data submitted successfully'); </script>
<?php
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
Upvotes: 2