Advertisement
Guest User

Untitled

a guest
May 27th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=”UTF-8">
  5. <title>Week 24/25</title>
  6. </head>
  7.  
  8. <body>
  9. Login:
  10. <br>
  11. <br>
  12. <form action="" method="get">
  13. First name:<br><input type="text" name="first_name"><br>
  14. Surname:<br><input type="text" name="last_name"><br>
  15. Email:<br><input type="text" name="email"><br><br>
  16. <input type="submit" name="register" value="Register">
  17. </form>
  18.  
  19. <?php
  20. if(isset($_REQUEST['register'] ))
  21. {
  22. if(empty($_GET["first_name"]) || empty($_GET["last_name"]) || empty($_GET["email"]))
  23. {
  24. echo "Please complete all fields.";
  25. }
  26. else
  27. {
  28. if (!filter_var($_GET["email"], FILTER_VALIDATE_EMAIL) === false)
  29. {
  30. echo 'Thanks ', $_GET["first_name"], ' ', $_GET["last_name"], ' for registering ', $_GET["email"], ' with us.';
  31. }
  32. else
  33. {
  34. echo("Please enter a valid email address");
  35. }
  36. }
  37. }
  38. ?>
  39.  
  40. <br>
  41. <br>
  42. Connect to MySQL Database:
  43. <br>
  44. <br>
  45. <form action="" method="get" autocomplete="on">
  46. Username:<br><input type="text" name="username" placeholder="scc_130"> scc_130<br>
  47. Password:<br><input type="password" name="password" placeholder="golf-87-solo"> golf-87-solo<br>
  48. Table:<br>
  49. <select name="table" align="center">
  50. <option value="blank">Select a table</option>
  51. <option value="population">Population</option>
  52. <option value="company">Company</option>
  53. <option value="fruit">Fruits</option>
  54. </select><br>
  55. View:<br>
  56. <select name="view" align="center">
  57. <option value="table">Table</option>
  58. <option value="chart">Google Chart</option>
  59. </select><br><br>
  60. <input type="submit" name="connect" value="Submit">
  61. <br>
  62. <br>
  63. </form>
  64.  
  65. <?php
  66. if(isset($_REQUEST['connect'] ))
  67. {
  68. require_once('connect.php');
  69.  
  70. if($_GET["view"] == 'table')
  71. {
  72. if($_GET["table"] == 'blank')
  73. {
  74. echo "Please select a table";
  75. }
  76.  
  77. if($_GET["table"] == 'population')
  78. {
  79. try{
  80. $query = "SELECT city AS Cities, people AS Population FROM population ORDER BY people DESC";
  81. $statement = $db->query($query);
  82.  
  83. echo "<table border='1'>
  84. <tr>
  85. <th>Cities</th>
  86. <th>Population</th>
  87. </tr>";
  88. while($row = $statement->fetch(PDO::FETCH_ASSOC))
  89. {
  90. echo "<tr>";
  91. echo "<td>" . $row['Cities'] . "</td>";
  92. echo "<td>" . $row['Population'] . "</td>";
  93. echo "</tr>";
  94. }
  95. echo "</table>";
  96. }
  97. catch(PDOException $e){
  98. $message = '<p>Something went wrong!</p><p>' . $e->getMessage(). '</p>';
  99. }
  100. }
  101.  
  102. if($_GET["table"] == 'company')
  103. {
  104. try{
  105. $query = "SELECT Sales, Expenses, Year FROM company ORDER BY Year DESC";
  106. $statement = $db->query($query);
  107.  
  108. echo "<table border='1'>
  109. <tr>
  110. <th>Sales</th>
  111. <th>Expenses</th>
  112. <th>Year</th>
  113. </tr>";
  114. while($row = $statement->fetch(PDO::FETCH_ASSOC))
  115. {
  116. echo "<tr>";
  117. echo "<td>" . $row['Sales'] . "</td>";
  118. echo "<td>" . $row['Expenses'] . "</td>";
  119. echo "<td>" . $row['Year'] . "</td>";
  120. echo "</tr>";
  121. }
  122. echo "</table>";
  123. }
  124. catch(PDOException $e){
  125. $message = '<p>Something went wrong!</p><p>' . $e->getMessage(). '</p>';
  126. }
  127. }
  128. if($_GET["table"] == 'fruit')
  129. {
  130. try{
  131. $query = "SELECT fruit_name AS Fruit, amount AS Quantity FROM fruits ORDER BY Fruit ASC";
  132. $statement = $db->query($query);
  133.  
  134. echo "<table border='1'>
  135. <tr>
  136. <th>Fruit</th>
  137. <th>Quantity</th>
  138. </tr>";
  139. while($row = $statement->fetch(PDO::FETCH_ASSOC))
  140. {
  141. echo "<tr>";
  142. echo "<td>" . $row['Fruit'] . "</td>";
  143. echo "<td>" . $row['Quantity'] . "</td>";
  144. echo "</tr>";
  145. }
  146. echo "</table>";
  147. }
  148. catch(PDOException $e){
  149. $message = '<p>Something went wrong!</p><p>' . $e->getMessage(). '</p>';
  150. }
  151. }
  152. }
  153. if($_GET["view"] == 'chart')
  154. {
  155. if($_GET["table"] == 'blank')
  156. {
  157. echo "Please select a table<br>";
  158. }
  159.  
  160. if($_GET["table"] == 'population')
  161. {
  162. function generateGoogleChart()
  163. {
  164. //Get the data from the database
  165. $query = "SELECT City, People FROM population";
  166. $result = $db->query($query);
  167.  
  168. $table = array();
  169. $table['cols'] = array(
  170. array('label' => 'City', 'type' => 'string'),
  171. array('label' => 'People', 'type' => 'number')
  172. );
  173.  
  174. $rows = array();
  175. while($r = mysql_fetch_assoc($sth)) {
  176. $temp = array();
  177. // the following line will be used to slice the Pie chart
  178. $temp[] = array('v' => (string) $r['City']);
  179. $temp[] = array('v' => (int) $r['people']);
  180. $rows[] = array('c' => $temp);
  181. }
  182.  
  183. $table['rows'] = $rows;
  184. $jsonTable = json_encode($table);
  185. }
  186. }
  187. }
  188. }
  189. ?>
  190.  
  191. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  192. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  193. <script type="text/javascript">
  194. google.load('visualization', '1.0', {'packages':['corechart']});
  195. google.setOnLoadCallback(drawChart);
  196. function drawChart() {
  197.  
  198. var data = new google.visualization.DataTable(<?=$jsonTable?>);
  199. var options = {
  200. 'width':400,
  201. 'height':400};
  202. var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  203. chart.draw(data, options);
  204. }
  205. </script>
  206.  
  207. <div id="chart_div"></div>
  208.  
  209. </body>
  210. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement