I require some help in figuring out why I’m getting an error while submitting a contact form that I created. My goal is to enable my Form from my “Contact Us” page of my site to send any submitted data to my database. I used this video as a guide to accomplish the goal of my project, but alas, it is not working. Perhaps I am doing something wrong, and hence I am creating this post.
This is the error I am getting after filling out all the necessary details and submitting the form.
I am fairly new to PHP and have limited experience in HTML, but even after searching for some help online to see if others had a similar problem and trying a few different things (mainly changing some variables or deleting others), I did not manage to fix the issue. The problem most definitely lies in my code, but I am unable to see where exactly. Please take a look at my form code in html:
<form class="rd-form rd-form-variant-2 rd-mailform" data-form-output="form-output-global" data-form-type="contact" method="post" action="process.php">
<div class="row row-14 gutters-14">
<div class="col-md-4">
<div class="form-wrap">
<input class="form-input" id="firstnamelastname" type="text" name="firstnamelastname" data-constraints="@Required">
<label class="form-label" for="firstnamelastname">ФИО</label>
</div>
</div>
<div class="col-md-4">
<div class="form-wrap">
<input class="form-input" id="email" type="email" name="email" data-constraints="@Email @Required">
<label class="form-label" for="email">Электронная почта</label>
</div>
</div>
<div class="col-md-4">
<div class="form-wrap">
<input class="form-input" id="phone" type="text" name="phone" data-constraints="@Numeric">
<label class="form-label" for="phone">Номер телефона</label>
</div>
</div>
<div class="col-12">
<div class="form-wrap">
<label class="form-label" for="message">Сообщение</label>
<textarea class="form-input textarea-lg" id="message" name="message" data-constraints="@Required"></textarea>
</div>
</div>
</div>
<button class="button button-primary button-pipaluk" type="submit">Отправить сообщение</button>
</form>
I apologize in advance if this is too much code to sit through.
What follows is my config.php file:
<?php
define("DB_HOST","localhost");
define("DB_USER","root");
define("DB_PASSWORD","");
define("DB_DATABASE","Museum")
$mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
?>
Lastly, my process.php:
<?php
include("config.php");
extract($_POST);
$query = "INSERT INTO 'contact-data' ('firstnamelastname','phone','email','message') VALUES ('".$firstnamelastname."','".$phone."','".$email."','".$message."')";
$result = $mysqli->query($query);
if(!$result){
echo "Something went Wrong".$mysqli->err;
}
echo "Thanks you for submitting your Querry";
$mysqli->close();
print_r($_POST);
?>
Submitting the form does nothing but the display the error previously mentioned and shown. None of messages written in process.php are sent back to me to confirm that any values were submitted/sent to the database.Here is the database I have created to receive the submittions from the forms.
Please feel free to ask for more information about the matter, I am determined to get this to work 🙂 Or if you have a better guide/instructions on how to accomplish my goal, I would appreciate if you could direct me to it.