Advertisement
Guest User

form

a guest
Sep 29th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. if ($_SERVER['REQUEST_METHOD'] == 'POST') //was da form submitted?
  2.  
  3. //Let's get the things big brother sent
  4. $address = $_POST["addy"];
  5. $name = $_POST["fname"];
  6.  
  7. //start mysql thingie
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "";
  11. $dbname = "contacts";
  12.  
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17. die("Connection failed: " . $conn->connect_error);
  18. }
  19.  
  20. //your code is actually good, let's keep it
  21. $sql = "INSERT INTO list ( firstname, lastname, organization, addy, phone1, phone2, email ) VALUES ($fname,'{conn->real_escape_string($_POST["Lastname"] )}','{conn->real_escape_string($_POST["organization"] )}','{conn->real_escape_string($_POST["addy"] )}', '{conn->real_escape_string($_POST["phone1"] )}', '{conn->real_escape_string($_POST["phone1"] )}', '{conn->real_escape_string($_POST["phone2"] )}','{conn->real_escape_string($_POST["email"] )}') ";
  22. $insert = $mysqli -> query($sql);
  23.  
  24. if ($insert){
  25. echo "Success! Row ID: {mysqli-> insert_id}";
  26. }else {
  27. die("Error: {$mysqli->errno} : {$mysqli->error}");
  28. }
  29.  
  30. $conn->close();
  31.  
  32. }//closing that if (form submited)
  33. else {
  34. //default page - if nothing was submited or it's first access
  35. ?>
  36.  
  37. <html>
  38. <head>
  39. <meta charset="UTF-8">
  40. <title>Contact List</title>
  41. </head>
  42. <body>
  43. <form method="post" action="">
  44. First name:<br>
  45. <input type="text" name="firstname"><br>
  46. Last name:<br>
  47. <input type="text" name="lastname"><br>
  48. Organization:<br>
  49. <input type="text" name="organization"><br>
  50. Address:<br>
  51. <input type="text" name="addy"><br>
  52. Phone 1:<br>
  53. <input type="text" name="phone1"><br>
  54. Phone 2:<br>
  55. <input type="text" name="phone2"><br>
  56. Email:<br>
  57. <input type="text" name="email"><br><br>
  58. <input type="submit" value="Submit">
  59. </form>
  60. </body>
  61. </html>
  62.  
  63. <? } >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement