Advertisement
RahulShaw

Insert into DB

Sep 10th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Insert From Form</title>
  5. </head>
  6. <body>
  7.     <form action="index.php" method="POST">
  8.         <input type="text" name="one"/>
  9.         <br>
  10.         <input type="text" name="two"/>
  11.         <br>
  12.         <input type="submit" value="Submit"/>
  13.     </form>
  14. </body>
  15. </html>
  16.  
  17. <?php
  18.            
  19.             if(isset($_POST['one']) && isset($_POST['two']) &&!empty($_POST['one'])
  20.                 &&!empty($_POST['two'])){
  21.  
  22.                
  23.             $servername = "localhost";
  24.             $username = "root";
  25.             $password = "root";
  26.             $dbname = "help";
  27.  
  28.             // Create connection
  29.             $con = mysqli_connect($servername, $username, $password, $dbname);
  30.             // Check connection
  31.             if (!$con) {
  32.                 die("Connection failed: " . mysqli_connect_error());
  33.             }
  34.  
  35.             $one = mysqli_real_escape_string($con, $_POST['one']);
  36.             $two = mysqli_real_escape_string($con, $_POST['two']);
  37.  
  38.  
  39.             $sql = "INSERT INTO value (one,two)
  40.                     VALUES('$one', '$two')";
  41.            
  42.  
  43.             if (!mysqli_query($con, $sql)) {
  44.                         die("ERROR : ".mysqli_error($con));
  45.                     }
  46.             else{
  47.                
  48.                 echo "Done!";
  49.  
  50.              }
  51.  
  52.            }
  53.  
  54.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement