Guest User

Untitled

a guest
Jan 19th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <FORM>
  2. ID: <input type="text" name="id"><br />
  3. NM: <input type="text" name="nm"><br />
  4. Company: <input type="text" name="company"><br />
  5. Address: <input type="text" name="address"><br />
  6. City: <input type="text" name="city"><br />
  7. Zip: <input type="text" name="zip"><br />
  8. State: <input type="text" name="state"><br />
  9. Phone: <input type="text" name="phone"><br />
  10. Website: <input type="text" name="web_site"><br />
  11. </FORM>
  12.  
  13. <?php
  14. $agent_nm = $_POST['nm']; // gather all the variables
  15. $company = $_POST['company'];
  16. $address = $_POST['address'];
  17. $city = $_POST['city'];
  18. $zip = $_POST['zip'];
  19. $state = $_POST['state'];
  20. $phone = $_POST['phone'];
  21. $web_site = $_POST['web_site'];
  22. $batch_id = $_POST['batch_id']; // added batch id
  23. //connect
  24. $conn = new mysqli('local', 'admin', 'pass', 'DB');
  25. if(mysqli_connect_errno()) {
  26. exit('Connect failed: '. mysqli_connect_error());
  27. }
  28. //generate the query (doesn't add id because id is autoincremented)
  29. $query = "INSERT INTO t_agent VALUES (NULL, " . $agent_nm . ", " . $company . ", " . $address . ", " . $city . ", " . $zip . ", " . $state . ", " . $phone . ", " . $web_site . ", " . $batch_id . ")";
  30.  
  31. //insert and close.
  32. mysqli_query($conn, $query);
  33. mysqli_close($conn);
  34.  
  35. <form method="post" action="process.php" id="myForm" name="myForm" >
  36. <label for="ID">ID</label>: <input type="text" name="ID" /><br />
  37. <label for="nm">NM:</label> <input type="text" name="nm"><br />
  38. <label for="company">Company:</label> <input type="text" name="company"><br />
  39. <label for="address">Address:</label> <input type="text" name="address"><br />
  40. <label for="city">City</label>: <input type="text" name="city"><br />
  41. <label for="zip">Zip</label>: <input type="text" name="zip"><br />
  42. <label for="state">State</label>: <input type="text" name="state"><br />
  43. <label for="phone">Phone</label>: <input type="text" name="phone"><br />
  44. <label for="web_site">Website</label>: <input type="text" name="web_site"><br />
  45. <input type="submit" name="submit" />// this is your submit button
  46. </form>
  47.  
  48. //get your inputs from the form
  49. $ID = $_POST['ID'];
  50. //do the same for each of the text inputs
  51.  
  52. <?php
  53. $host= "xxx";
  54. $username="xxx";
  55. $password="xxx";
  56. $database="xxx ";
  57.  
  58. // Gets data from URL parameters
  59.  
  60. $name = $_POST['nm'];
  61. //Repeate for all other parameters
  62.  
  63. // Opens a connection to a MySQL server
  64. try {
  65.  
  66. // DBH means "DB Handle"
  67.  
  68. // MySQL with PDO_MYSQL
  69. $DBH = new PDO("mysql:host=$host;dbname=$database", $username, $password);
  70.  
  71. }
  72. catch(PDOException $e) {
  73. echo $e->getMessage();
  74. }
  75. // STH means "Statement Handle"
  76. $STH = $DBH->prepare("INSERT INTO mytable ( id, nm,company,address,city,zip,state,phone,web_site ) values ( NULL,:nm,:company,:address,:city,:zip,:state,:phone,:web_site)");
  77. $STH->bindParam(':name', $name);
  78. //Repeate for all other parameters
  79. $STH->execute();
  80.  
  81. //# close the connection
  82. $DBH = null;
  83. ?>
Add Comment
Please, Sign In to add comment