Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. // Check if button is pressed
  4. if(isset($_POST['submit'])) {
  5.    
  6.     // Check if any comment is written
  7.     if(empty($_POST['comment'])) {
  8.         $noCom = 'Please dont send empty comments!!!';
  9.     }
  10.    
  11.     // Button pressed and comment is not empty
  12.     else {
  13.         $DBHOST = '127.0.0.1';
  14.         $DBUSER = 'root';
  15.         $DBPASS = '';
  16.         $DBNAME = 'tastyfood';
  17.    
  18.         // Create connection
  19.         $conn = new mysqli($DBHOST, $DBUSER, $DBPASS, $DBNAME);
  20.        
  21.         // Check connection
  22.         if($conn->connect_error) {
  23.             die("Connection failed: " . $conn->connect_error);
  24.             echo 'Connection failed!';
  25.         }
  26.        
  27.         // Proceed if connection is established
  28.         else {
  29.             $connState = 'Connected sucessfully';
  30.  
  31.             $comment = $_POST['comment'];      
  32.  
  33.             // Prepare to post comment to database
  34.             $stmt = $conn->prepare("INSERT INTO comment (comment) VALUE (?)");
  35.             $stmt->bind_param("s", $comment);
  36.        
  37.             // Post comment to database
  38.             $stmt->execute();
  39.    
  40.         }
  41.     }      
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement