Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Check if button is pressed
- if(isset($_POST['submit'])) {
- // Check if any comment is written
- if(empty($_POST['comment'])) {
- $noCom = 'Please dont send empty comments!!!';
- }
- // Button pressed and comment is not empty
- else {
- $DBHOST = '127.0.0.1';
- $DBUSER = 'root';
- $DBPASS = '';
- $DBNAME = 'tastyfood';
- // Create connection
- $conn = new mysqli($DBHOST, $DBUSER, $DBPASS, $DBNAME);
- // Check connection
- if($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- echo 'Connection failed!';
- }
- // Proceed if connection is established
- else {
- $connState = 'Connected sucessfully';
- $comment = $_POST['comment'];
- // Prepare to post comment to database
- $stmt = $conn->prepare("INSERT INTO comment (comment) VALUE (?)");
- $stmt->bind_param("s", $comment);
- // Post comment to database
- $stmt->execute();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement