Advertisement
Guest User

Untitled

a guest
Feb 4th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement