Advertisement
Guest User

Untitled

a guest
Apr 12th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost:3306";
  4. $username = "xgx2741";
  5. $password = "Izaacmarc20";
  6. $dbname = "PostDB";
  7. $statcode = "";
  8. $status = "";
  9. $share = "";
  10. $date = "";
  11. $ptype = "";
  12.  
  13.  
  14. if($_SERVER["REQUEST_METHOD"] == "POST") {
  15.  
  16. $statcode = user_input($_POST["statcode"]);
  17.  
  18. if(strcmp($_POST["statcode"]) == 0){
  19. echo "<span style = 'font-size: 30px; font-family: Arial, tahoma, sans-serif; color: red'> Please Enter a valid Status Code </span>;";
  20. } else {
  21. $statcode = user_input($_POST["statcode"]);
  22. }
  23.  
  24. if(strcmp($_POST["status"]) == 0) {
  25. echo "<span style = 'font-size: 16px; font-family: Arial, tahoma, sans-serif; color: red'> Please Enter a Status</span>;";
  26. } else {
  27. $status = user_input($_POST["status"]);
  28. }
  29.  
  30. if(strcmp($_POST["share"]) == 0) {
  31. echo "<span style = 'font-size: 16px; font-family: Arial, tahoma, sans-serif; color: red'> Opps you forgot to select a share preference</span>;";
  32. } else {
  33. $share = user_input($_POST["share"]);
  34. }
  35.  
  36. $date = user_input($_POST["date"]);
  37.  
  38. if(strcmp($_POST["ptype"]) == 0) {
  39. echo "<span style = 'font-size: 16px; font-family: Arial, tahoma, sans-serif; color: red'> Opps you forgot to select a permission type</span>;";
  40. } else {
  41. $ptype = user_input($_POST["ptype"]);
  42. }
  43.  
  44.  
  45. }
  46.  
  47. function user_input($data)
  48. {
  49. $data = trim($data);
  50. $data = stripslashes($data);
  51. $data = htmlspecialchars($data);
  52. return $data;
  53. }
  54.  
  55. echo $statcode;
  56. echo $status;
  57. echo $share;
  58. echo $date;
  59. echo $ptype;
  60.  
  61. // Create connection
  62. $conn = new mysqli($servername, $username, $password, $dbname);
  63. // Check connection
  64. if ($conn->connect_error) {
  65. die("Connection failed: " . $conn->connect_error);
  66. }
  67.  
  68. $sql = "CREATE TABLE StatusData {
  69. statcode VARCHAR(10) NOT NULL,
  70. status VARCHAR(80) NOT NULL,
  71. share VARCHAR(50),
  72. datetime VARCHAR(10),
  73. ptype VARCHAR(50)
  74. )}";
  75.  
  76. if ($conn->query($sql) === TRUE) {
  77. echo "Table has been successfully created";
  78. } else {
  79. echo "Error creating table: " . $conn->error;
  80. }
  81.  
  82.  
  83. $sql = "INSERT INTO StatusData (statcode, status, share, datetime, ptype)
  84. VALUES ($statcode, $status, $share, $date, $ptype)";
  85.  
  86. if ($conn->query($sql) === TRUE) {
  87. echo "New Status Successfully Updated";
  88. } else {
  89. echo "Error: " . $sql . "<br>" . $conn->error;
  90. }
  91.  
  92. $conn->close();
  93.  
  94.  
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement