SHARE
TWEET

Untitled

a guest Feb 4th, 2016 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- index.html-->
  2. <form action="process.php" method="post">
  3.  
  4.   <input type="text" name="first_name" placeholder="First Name" /><br/>
  5.    <input type="text" name="last_name" placeholder="Last Name" /><br/>
  6.  
  7.       <button type="submit" name="submit"></button>
  8. </form>
  9.  
  10. //database.php
  11. $dbhost = "localhost";
  12. $dbuser = "root";
  13. $dbpass = "xxxx";
  14. $dberror1 = "Could not connect to the database!";
  15. $dberror2 = "Could not find selected table!";
  16.  
  17. // Connection to the database, Already tried this with echo statement and works
  18. $conn  = mysqli_connect($dbhost, $dbuser, $dbpass) or die ($dberror1);
  19.  
  20. // Selecting the database to connect to
  21. $select_db = mysqli_select_db($conn, 'mainbase') or die ($dberror2);
  22.  
  23. //process.php
  24. <?php include 'database.php';
  25.  
  26.  if(isset($_POST['submit'])) {
  27. // Creating variables to store form values
  28. $first_name= $_POST['first_name'];
  29. $last_name=$_POST['last_name'];
  30.  
  31.  
  32. //Executing the query
  33. mysqli_query($conn, " INSERT INTO 'candidates'('first_name', 'last_name') //Values in 'candidates' table on phpmyadmin
  34. VALUES ('$first_name','$last_name')");/*variables from above*/
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top