Advertisement
Guest User

Untitled

a guest
Apr 14th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. function sql() {
  4. $servername = "";
  5. $username = "";
  6. $password = "";
  7. $dbname = "";
  8.  
  9. // Create connection
  10. $conn = mysqli_connect($servername, $username, $password, $dbname);
  11.  
  12. // Check connection
  13. if (!$conn) {
  14.    
  15.     global $success;
  16.     $success = false;
  17.     return;
  18.     //die("Connection failed: " . mysqli_connect_error());
  19. }
  20.  
  21. $sqlid = "SELECT id FROM contact ORDER BY id DESC LIMIT 1";
  22. $result = mysqli_query($conn, $sqlid);
  23. $row=mysqli_fetch_assoc($result);
  24. $last_id = $row["id"];
  25.  
  26. if ($last_id == "") {
  27.     $fromid = "0";
  28. } else {
  29.     $fromid = $last_id+1;
  30. }
  31.  
  32.  
  33. global $fromname, $frommail, $name_company, $mail_company, $phone_company, $adress_company, $city_company, $country_company, $text;
  34.  
  35. $stmt = mysqli_stmt_init($conn);
  36. $sql = mysqli_stmt_prepare($stmt, 'INSERT INTO contact (id, name, mail, company, mail_company, phone_company, adress_company, city, country, message)
  37. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
  38. mysqli_stmt_bind_param($sql, 'isssssssss', $fromid, $fromname, $frommail, $name_company, $mail_company, $phone_company, $adress_company, $city_company, $country_company, $text);
  39. mysqli_stmt_execute($stmt);
  40. mysqli_stmt_error($stmt); //debugging
  41.  
  42. print_r($_POST);
  43.  
  44. /* $sql = "INSERT INTO contact (id, name, mail, company, mail_company, phone_company, adress_company, city, country, message)
  45. VALUES ('$fromid', '$fromname', '$frommail', '$name_company', '$mail_company', '$phone_company', '$adress_company', '$city_company', '$country_company', '$text')"; */
  46.  
  47. if (mysqli_query($conn, $sql)) {
  48.     //echo "New record created successfully";
  49.     global $success;
  50.     $success = true;
  51. } else {
  52.     echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  53. }
  54. mysqli_stmt_close($stmt);
  55. mysqli_close($conn);
  56. }
  57.  
  58. sql();
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement