29.include.cache.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 1);
  4. if(isset($_POST['PlantcsvForm'])) {
  5. $sql = null;
  6. $con = mysqli_connect("localhost", "root", "R3M0T31", "cropmonitor");
  7. //set todays date
  8. $date = date("Y-m-d H:i:s");
  9. //Get figures
  10. $email = (isset($_POST["email"])) ? $_POST["email"] : "";
  11. $client_name = (isset($_POST["name"])) ? $_POST["name"] : "";
  12. $site_address = (isset($_POST["site_address"])) ? $_POST["site_address"] : "";
  13. $state_postcode = (isset($_POST["state_postcode"])) ? $_POST["state_postcode"] : "";
  14. $analysis_type = (isset($_POST["analysis_type"])) ? $_POST["analysis_type"] : "";
  15. $lab_no = (isset($_POST["lab_no"])) ? $_POST["lab_no"] : "";
  16. $batch_no = (isset($_POST["batch_no"])) ? $_POST["batch_no"] : "";
  17. $date_sampled = (isset($_POST["date_sampled"])) ? $_POST["date_sampled"] : "";
  18. $sample_id = (isset($_POST["sample_id"])) ? $_POST["sample_id"] : "";
  19. $site_id = (isset($_POST["site_id"])) ? $_POST["site_id"] : "";
  20. $crop_type = (isset($_POST["crop_type"])) ? $_POST["crop_type"] : "";
  21. $n = (isset($_POST["n"])) ? $_POST["n"] : "";
  22. $p = (isset($_POST["p"])) ? $_POST["p"] : "";
  23. $k = (isset($_POST["k"])) ? $_POST["k"] : "";
  24. $s = (isset($_POST["s"])) ? $_POST["s"] : "";
  25. $mg = (isset($_POST["mg"])) ? $_POST["mg"] : "";
  26. $ca = (isset($_POST["ca"])) ? $_POST["ca"] : "";
  27. $na = (isset($_POST["na"])) ? $_POST["na"] : "";
  28. $fe = (isset($_POST["fe"])) ? $_POST["fe"] : "";
  29. $mn = (isset($_POST["mn"])) ? $_POST["mn"] : "";
  30. $zn = (isset($_POST["zn"])) ? $_POST["zn"] : "";
  31. $cu = (isset($_POST["cu"])) ? $_POST["cu"] : "";
  32. $b = (isset($_POST["b"])) ? $_POST["b"] : "";
  33. $m = (isset($_POST["m"])) ? $_POST["m"] : "";
  34. $co = (isset($_POST["co"])) ? $_POST["co"] : "";
  35. $se = (isset($_POST["se"])) ? $_POST["se"] : "";
  36. $ch = (isset($_POST["cl"])) ? $_POST["cl"] : "";
  37. //$rand = substr(md5(microtime()),rand(0,26),5);
  38. $rand = mt_rand(10000, 99999);
  39. // Check connection
  40. if (mysqli_connect_errno())
  41. {
  42. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  43. }
  44. $sql = mysqli_query($con, "INSERT into `plant_records`
  45. (
  46. date,
  47. email,
  48. client_name,
  49. site_address,
  50. state_postcode,
  51. analysis_type,
  52. lab_no,
  53. batch_no,
  54. date_sampled,
  55. sample_id,
  56. site_id,
  57. crop_type,
  58. n,
  59. p,
  60. k,
  61. s,
  62. mg,
  63. ca,
  64. na,
  65. fe,
  66. mn,
  67. zn,
  68. cu,
  69. b,
  70. m,
  71. co,
  72. se,
  73. cl,
  74. rand
  75. ) VALUES (
  76. '" . $date . "',
  77. '" . $email . "',
  78. '" . $client_name . "',
  79. '" . $site_address . "',
  80. '" . $state_postcode . "',
  81. '" . $analysis_type . "',
  82. '" . $lab_no . "',
  83. '" . $batch_no . "',
  84. '" . $date_sampled . "',
  85. '" . $sample_id . "',
  86. '" . $site_id . "',
  87. '" . $crop_type . "',
  88. '" . $n . "',
  89. '" . $p . "',
  90. '" . $k . "',
  91. '" . $s . "',
  92. '" . $mg . "',
  93. '" . $ca . "',
  94. '" . $na . "',
  95. '" . $fe . "',
  96. '" . $mn . "',
  97. '" . $zn . "',
  98. '" . $cu . "',
  99. '" . $b . "',
  100. IF('" . $m . "'='',NULL,'" . $m . "'),
  101. IF('" . $co . "'='',NULL,'" . $co . "'),
  102. IF('" . $se . "'='',NULL,'" . $se . "'),
  103. IF('" . $cl . "'='',NULL,'" . $cl . "'),
  104. '" . $rand . "'
  105. )" );
  106. $insert_id = mysqli_insert_id($con);
  107. if ($sql === TRUE)
  108. {
  109. //echo "success"; //CHECKING
  110. // forward to results page if successfully inserts to database
  111. echo "<script>location.href = '[[~26]]?rand=" . $rand . "&cid=" . $sample_id . "&rid=" . $insert_id . "&stid=" .$crop_type . "','_blank';</script>";
  112. } else {
  113. die(mysqli_error($con)); // TODO: better error handling
  114. //echo "User Profile incorrect";
  115. }
  116. }
  117. return;