I want to send my html form data to my database which I have created using XAMPP. But, for some reason, the submit button is not working.
This is my html code:-
<form id="contact" action="contact.php" method="post" >
<div >
<fieldset >
<input type="text" name="name2" id="name" placeholder="Your Name" required>
</fieldset>
<fieldset >
<input type="email" name="email2" id="email" placeholder="Your Email" required>
</fieldset>
</div>
<fieldset >
<input type="text" name="phone2" id="phone" placeholder="Your Phone Number" required>
</fieldset>
<fieldset >
<input type="text" name="subject2" id="subject" placeholder="Subject" required>
</fieldset>
<fieldset >
<textarea name="message2" rows="5" placeholder="Message" required></textarea>
</fieldset>
<fieldset >
<button type="submit" name="submit" id="contact-submit">Send Message</button>
</fieldset>
</form>
This is my contact.php code:-
<?php
$name = $_POST['name2'];
$fromEmail = $_POST['email2'];
$phone = $_POST['phone2'];
$subject = $_POST['subject2'];
$message = $_POST['message2'];
//Database Connection
$conn = new mysqli('localhost','root','','contactus');
if ($conn->connect_error) {
die('Connection Failed : '.$conn->connect_error);
} else {
$stmt = $conn->prepare("insert into contact(Name, Email, Phone No., Subject, Message)
values(?,?,?,?,?)");
$stmt->bind_param("ssiss",$name,$fromEmail,$phone,$subject,$message);
$execval = $stmt->execute();
echo $execval;
echo "Sent Successfully";
$stmt->close();
$conn->close();
}
?>
CodePudding user response:
In order for the system to properly process the data field Phone No.
in db operation, Please enclose it by backticks in your query
Change
$stmt = $conn->prepare("insert into contact(Name, Email, Phone No., Subject, Message) .....
to
$stmt = $conn->prepare("insert into contact(Name, Email, `Phone No.`, Subject, Message) .....
CodePudding user response:
The Submit-Button is working just fine if you isolate the issue (Submit button in a form not sending data?) and check the networking tab in the dev-tools.