Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>organiser page></title>
  5. <style type="text/css">
  6. th,td{border:1px solid black; width: 150px;}
  7. </style>
  8. </head>
  9. <body>
  10. <h3>WELCOME TO YOUR ORGANISER PAGE</h3>
  11. </body>
  12. <?php
  13. //Start or resume a session
  14. session_start();
  15. //!!Debug (I dont use login.php, I use this to bypass login.php. so remove this sen)!!
  16. //$_SESSION['volunteermail'] = "john@hotmail.com";
  17. if ( !isset( $_SESSION['organisermail'] ))
  18. {
  19. header('Location: organiser.php');
  20. exit;
  21. }
  22. //connect to database
  23.  
  24. $db= new mysqli('localhost','root','','assignment1');
  25. if (mysqli_connect_error())
  26. {//display the details of any connection errors
  27. echo 'Error connecting to database:<br/>'.mysqli_connect_error();
  28. exit;
  29. }
  30. //echo'testing1';
  31.  
  32. if (isset($_POST['time_id']))
  33. {
  34. //validate that user can't add already added time slot
  35. $query= "SELECT time_id FROM volunteer_times WHERE time_id ='" . $_POST['time_id'] . "' AND volunteer_email='" . $_SESSION['volunteermail'] . "'";
  36. //echo $query."<br>";
  37. $results=$db->query($query);
  38.  
  39.  
  40. if ($results-> num_rows > 0)
  41. {
  42. $error_message='Your data already exist, choose another.';
  43.  
  44. }
  45.  
  46. $query= "INSERT INTO volunteer_times VALUE(NULL,'" . $_SESSION['organisermail'] . "','" . $_POST['time_id'] . "','0','')";
  47. //echo'insert query';
  48. $result= $db->query($query);
  49.  
  50. if ($result)
  51. {
  52. echo'<p>User details inserted into database!</p>.';
  53. }else{
  54. echo mysqli_error($db);
  55. }
  56. }
  57.  
  58. //echo'testing2';
  59.  
  60.  
  61. $query = "SELECT * FROM volunteer_times AS v JOIN time_slot AS t ON v.time_id = t.time_id
  62. JOIN tasks AS ta ON v.task_id = ta.task_id
  63. JOIN volunteers as vl ON v.volunteer_email = vl.email" ;
  64.  
  65. //execute the query
  66. $results = $db-> query($query);
  67.  
  68. //show how many rows the query returned
  69. //echo '<p>'.$results->num_rows.' users found.</p>';
  70.  
  71. //start the table in which our user list will be shown
  72. echo '<table><tr>';
  73. echo'<th>Time Slot</th><th>Volunteer Name</th><th>Allocated Task</th><th>Details</th><th>Remove</th>';
  74. echo'</tr>';
  75. //loop through the results and display them
  76. while ($row=$results-> fetch_assoc())
  77. {
  78. $pos_query='SELECT * FROM time_slot WHERE time_id = '.$row['time_id'];
  79. $pos_results=$db->query($pos_query);
  80. $pos_row=$pos_results->fetch_assoc();
  81. echo '<td>'.$pos_row['time_slot_name'].'</td>';
  82. $pos_query2='SELECT * FROM tasks WHERE task_id= '.$row['task_id'];
  83. $pos_results2=$db->query($pos_query2);
  84. $pos_row2=$pos_results2->fetch_assoc();
  85.  
  86. //$pos_query3='SELECT * FROM volunteers WHERE surname = '.$row['surname'];
  87. //$pos_results3=$db->query($pos_query3);
  88. //$pos_row3=$pos_results3->fetch_assoc();
  89. echo '<td>'.$row['first_name']." ".($row['surname']).'</td>';
  90.  
  91. echo '<td>'.$pos_row2['task_name'].'</td>';
  92.  
  93.  
  94. echo '<td>'.$row['description'].'</td>';
  95.  
  96.  
  97. echo '<td><a href="Allocatet.php?vol_time_id='.$row['vol_time_id'].'">Edit</a> </td></tr>';
  98.  
  99. //echo '<td><a href="Allocatet.php?vol_time_id">Edit</a> </td></tr>';
  100.  
  101. }
  102. echo'</table>';
  103. //echo'testing3';
  104.  
  105. //test the clearslot
  106. if(isset($_POST['Clearslot']))
  107. {
  108. $query="UPDATE volunteer_times WHERE SET description=NULL, task_id=0 WHERE vol_time_id='".$row['vol_time_id']."'";
  109. $result= $db->query($query);
  110.  
  111. if ($result)
  112. {
  113. echo'<p>User details cleared</p>.';
  114. }
  115. }
  116.  
  117. ?>
  118. <form name="clearslot" method="post" action="VolunteerTimeSlots.php">
  119. <table style="width: 200px; border: 0px;" cellspacing="1" cellpadding="1">
  120. <input type="submit" name="submit" value="Clearslot" /></td>
  121.  
  122. </table>
  123. </form>
  124. <?php echo '<p><a href="logout.php">Log Out</a></p>'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement