PHP Feedback Form
From w3cyberlearnings
Contents |
PHP Feedback form
This is a feedback form and it uses MySQL database as a storage. When user submits the form, the user information will store in the feedback table. The feedback.php page will redirect user to the thankyou.php page. However, if the user do not fill in all the fields in the form. The feedback.php page will display message to the user and ask user to fill in the form again. Again you can use cron job to send user email after user have successfully submitted his or her feedback.
Table: Store feedback form data
CREATE TABLE feedback ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), tel VARCHAR(15), email VARCHAR(50), description VARCHAR(255) );
Step 1(feedback.php)
<?php $msg = ""; if (!empty($_POST['feedback'])) { $mysqli_db = new mysqli('localhost', 'root', 'yeething', 'my_db'); $name = $_POST['fb_name']; $tel = $_POST['fb_phone']; $email = $_POST['fb_email']; $description = $_POST['fb_description']; if (!empty($name) && !empty($tel) && !empty($email) && !empty($description)) { $query = 'INSERT INTO feedback(name, tel, email, description) VALUES(?,?,?,?)'; $requery = $mysqli_db->prepare($query); $requery->bind_param("ssss", $name, $tel, $email, $description); if ($requery->execute()) { header('location:thankyou.php?id=' . $requery->insert_id); } $mysqli_db->close(); } else { $msg = 'Enter your feeback!<br/>'; } } ?> <html> <head> <title>Feed-Back</title> </head> <body> <?php if (!empty($msg)) { echo $msg; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <table border="0"> <tr> <td>Name:</td> <td> <input type="text" name="fb_name" size="20" maxlength="20"/> </td> </tr> <tr> <td>Email:</td> <td> <input type="text" name="fb_email" size="20" maxlength="20" /> </td> </tr> <tr> <td>Tel/Phone:</td> <td> <input type="text" name="fb_phone" size="20" maxlength="20" /> </td> </tr> <tr> <td valign="top">Description:</td> <td> <textarea name="fb_description" rows="6" cols="40"></textarea> </td> </tr> <tr> <td colspan="2"> <input type="submit" name="feedback" value="Feed Back" /> </td> </tr> </table> </form> </body> </html>
Step 2(thankyou.php)
<html> <head> <title>Thank you</title> </head> <body> <?php $mysqli_db = new mysqli('localhost', 'root', 'yeething', 'my_db'); $query = 'SELECT * FROM feedback WHERE id=' . $_GET['id']; $myquery = $mysqli_db->query($query); $rows = $myquery->fetch_assoc(); echo 'Thank you for your feedback! <br/>'; echo 'Your email is ' . $rows['email']; $mysqli_db->close(); ?> </body> </html>
Output
Related Links
HTML Form