A Feedback form can be the most convenient way to understand how users feel about your products or services. The feedback or suggestion given by the end user can be of real help to improve your outcomes or the overall process.
A simple feedback form in PHP
Firstly, you create an HTML form to get the information you need for the evaluation. You can send this information to the people with decision power in your organization or save it in a database for generating reports or later review.
In this tutorial, we will save the information in the database.
Create the form
<!DOCTYPE html> <html> <head> <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> <style> *{box-sizing:border-box;} body{font-family: 'Open Sans', sans-serif; color:#333; font-size:14px; background-color:#dadada; padding:100px;} .form_box{width:400px; padding:10px; background-color:white;} input{padding:5px; margin-bottom:5px;} input[type="submit"]{border:none; outlin:none; background-color:#679f1b; color:white;} .heading{background-color:#ac1219; color:white; height:40px; width:100%; line-height:40px; text-align:center;} .shadow{ -webkit-box-shadow: 0px 0px 17px 1px rgba(0,0,0,0.43); -moz-box-shadow: 0px 0px 17px 1px rgba(0,0,0,0.43); box-shadow: 0px 0px 17px 1px rgba(0,0,0,0.43);} .pic{text-align:left; width:33%; float:left;} </style> <body> <div class="form_box shadow"> <form method="post" action="practice_ac.php"> <div class="heading"> Feedback Form in PHP </div> <br/> <p>What do you think about the quality of our blog?</p> <div> <div class="pic"> <img src="bad.png" alt=""> <br/> <input type="radio" name="quality" value="0"> Bad </div> <div class="pic"> <img src="neutral.png" alt=""> <br/> <input type="radio" name="quality" value="1"> Okay </div> <div class="pic"> <img src="good.png" alt=""> <br/> <input type="radio" name="quality" value="2"> Good </div> </div> <p>Do you have any suggestion for us? </p> <textarea name=" suggestion" rows="8" cols="40"></textarea> <input type="submit" name="submit" value="Submit Form"> </form> </div> </body> </html>
When the user clicks on “Submit Form,” the information will be sent to practice_ac.php
Create the database
Let’s create a simple table ‘feedback’ to store all the suggestions of the users. Off-course, this is not a complete solution. You can add more information like name, email, contact number of the user as well as IP, country, etc.
Now the file Practice_ac.php
<?php $q_score = $_POST['quality']; $feedback_txt = $_POST['suggestion']; $conn = mysqli_connect("localhost", "root","", "practice"); $query ="insert into feedback(quality_score, feedback)values($q_score, '$feedback_txt')"; $result = mysqli_query($conn, $query); if($result) echo 'Thank you for your feedback. We\'ll appreciate!'; else die("Something terrible happened. Please try again. "); ?>
After the feedback is submitted.
Comments