Guest User

Untitled

a guest
Aug 20th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set("display_errors", "on");
  4.  
  5. error_reporting(E_ALL + E_DEPRECATED);
  6.  
  7. session_start();
  8.  
  9. $username = $_POST['username'];
  10. $password = $_POST['password'];
  11. $created = '2010-11-30 15:17:44';
  12. $orgType = $_POST['orgType'];
  13. $orgName = $_POST['orgName'];
  14. $streetAddress = $_POST['streetAddress'];
  15. $suiteApt = $_POST['suiteApt'];
  16. $city = $_POST['city'];
  17. $state = $_POST['state'];
  18. $zipcode = $_POST['zipcode'];
  19. $phone = $_POST['phone'];
  20. $extension = $_POST['extension'];
  21. $fax = $_POST['fax'];
  22. $website = $_POST['website'];
  23. $contactFullName = $_POST['contactFullName'];
  24. $contactEmail = $_POST['contactEmail'];
  25. $contactPhone = $_POST['contactPhone'];
  26. $contactExtension = $_POST['contactExtension'];
  27.  
  28.  
  29. var_dump($_POST); //Used for troubleshooting, post was successful.
  30.  
  31. // Require the file which contains the database credentials.
  32. require('db.inc.php');
  33.  
  34. // Create a new database connection.
  35. $dbc = new mysqli($server, $db_user, $db_pass, $db);
  36.  
  37. if (mysqli_connect_errno()) {
  38. printf("Connect failed: %s\n", mysqli_connect_error());
  39. exit();
  40. }
  41.  
  42. // Was having a hard time executing the query, decided to hard-code the values in.
  43. //$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
  44. $stmt = $dbc->prepare("INSERT INTO organization (username, password, created, orgType, orgName,
  45. streetAddress, city, state, zipcode, phone,
  46. contactFullName, contactEmail, contactPhone)
  47. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);"
  48. );
  49.  
  50. if (!$stmt) {
  51. echo "Error: ".$dbc->error;
  52. exit;
  53. }
  54.  
  55. $stmt->bind_param('sssssssssssss',$username,$password,$created,$orgType,$orgName,$streetAddress,$city,
  56. $state,$zipcode,$phone,$contactFullName,$contactEmail,$contactPhone);
  57.  
  58.  
  59. //VALUES ('user','test',now(),'s','testCo','1234 mockingbird lane',
  60. // 'madison','WI','55555','1234567890','test user',
  61. // 'user@test.com','1234567890');");
  62. //INSERT INTO organization (username, password,created,orgType,orgName,streetAddress,city,state,zipcode,phone,contactFullName,contactEmail, contactPhone, contactExtension)
  63. //VALUES (?,?,now(),?,?,?,?,?,?,?,?,?,?);";
  64. //VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);");
  65.  
  66. // After all the trouble I had with the bind parameters, I ended up hard-coding values in for the "prepare" function. It worked.
  67. // Am now going to try using variables now. Success/fail notes to follow.
  68. // Using the $_POST variables did indeed work. Proved by viewing the table, it showed the incorrect time ($created = '2010-11-30 15:17:44';).
  69. // Will now try binding parameters once more, using "now()" first.
  70. // Turns out that I had completely forgotten to assign the data types as the first parameter in bind_param().
  71. // Changing bind_param() to remove $created (was hard-coded) and use now() in the VALUES portion of the prepare() method.
  72. // Didn't work. Needed $created to be hard-coded...stumped. Moving on.
  73.  
  74. $executedQuery = $stmt->execute();
  75.  
  76. if(!$executedQuery){
  77. echo "Error: ".$dbc->error;
  78. //die(mysqli_connect_error());
  79. exit;
  80. }
  81.  
  82. ?>
Add Comment
Please, Sign In to add comment