Advertisement
Guest User

Untitled

a guest
May 19th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset=”UTF-8">
  4. <title>Page Title</title>
  5. </head>
  6.  
  7. <body>
  8. <!--<form action="home.php" method="post">
  9. First name: <input type="text" name="FirstName"required><br>
  10. Second name: <input type="text" name= "SecondName"required><br>
  11. Email: <input type="text" name="Email"required><br>
  12. DB Login: <input type="text" name="db_login"required><br>
  13. DB Password:<input type="password" name="db_pass"required><br>
  14. <input type= "submit"> -->
  15.  
  16.  
  17. <table
  18. style="width:50%"
  19. align="center"
  20. border="4"
  21. cellspacing="4"
  22. cellpadding="8">
  23.  
  24. <tr>
  25. <td width="100" rowspan="2" bgcolor="DeepSkyBlue">
  26. <img src="php.png" alt="PHP logo" width="100" height="75"/></td>
  27. <td width="*" align="center" bgcolor="DarkSeaGreen"><font
  28. color="MintCream" size="+2" face="Courier New"><strong>MY LINK
  29. PAGE</strong></font></td>
  30. <td width="100" rowspan="2" bgcolor="Red">
  31. <img src="mysql.png" alt=" MYSQL logo" width="100" height="75"/></td>
  32. </tr>
  33.  
  34. <tr>
  35. <td bgcolor="LightSkyBlue">
  36. <table width="100%" border="1" cellspacing="2" cellpadding="2">
  37. <tr>
  38. <td width="50%" align="center" bgcolor="LightSeaGreen">
  39. <a href="main.php"> Home</a></td>
  40. <td width="50%" align="center" bgcolor="LightSeaGreen">
  41. <a href="ViewUsers.php"> View Users</a></td>
  42. </tr>
  43. </table>
  44. </td>
  45. </tr>
  46.  
  47.  
  48.  
  49. <tr> <!-- CONTENT ROW -->
  50. <td bgcolor="Orange">&nbsp;</td>
  51. <td bgcolor="Yellow" align="center">
  52. <form action="home.php" method="post">
  53. First name: <input type="text" name="FirstName"required><br>
  54. Second name: <input type="text" name= "SecondName"required><br>
  55. Email: <input type="text" name="Email"required><br>
  56. DB Login: <input type="text" name="db_login"required><br>
  57. DB Password:<input type="password" name="db_pass"required><br>
  58. <input type= "submit" name "loginsubmit" value="submit">
  59. </form>
  60. </td>
  61. <td width="10" bgcolor="Orange">&nbsp;</td>
  62. </tr>
  63.  
  64. <!--<tr>
  65. <td bgcolor="Orange">&nbsp;</td>
  66. <td bgcolor="Yellow" align="center">
  67. <p>
  68.  
  69. what area would you like to see?
  70. <select name="form_table">
  71. <option value=""> Select...</option>
  72. <option value ="company">Company</option>
  73. <option value ="fruits">Fruits</option>
  74. <option value ="population">Population</option>
  75.  
  76. </select>
  77.  
  78. </p>
  79. </td>
  80. <td width="10" bgcolor="Orange">&nbsp;</td>
  81. </tr>-->
  82.  
  83.  
  84.  
  85. <?php
  86. $firstname = $_POST["FirstName"];
  87. $secondname = $_POST["SecondName"];
  88.  
  89.  
  90. if (!empty( $_POST["FirstName"])){
  91. if(!preg_match("/^[a-zA-Z ]*$/", $firstname)){
  92. echo " First name should only contain characters";
  93. }
  94. else if (!empty( $_POST["SecondName"])){
  95. if(!preg_match ("/^[a-zA-Z ]*$/", $secondname)){
  96. echo "Second name should only contain characters";
  97. }
  98. else{
  99. echo "hello ", $firstname ," ", $secondname, ".";
  100. }
  101. }else{
  102. echo "Second name has not been entered, please enter a name.";
  103. }
  104.  
  105.  
  106. } else{
  107. echo "First Name has not been entered, please enter a name.";
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114. ?><br><br>
  115.  
  116.  
  117. <?php
  118. $email = $_POST["Email"];
  119. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  120. echo "Email isn't in an email format.";
  121. }else{
  122. if (!empty($_POST["email"])) {
  123. echo "Your email is: " , $email;
  124. }else{
  125. //echo "Your email is: " , $email;
  126. //echo "Email has not been entered.";
  127. }
  128. }
  129. ?><br><br>
  130.  
  131.  
  132. <?php //when the login button is pressed
  133. if(isset($_REQUEST['loginsubmit'])) //request, contains the contents of get, post and cookie
  134. {
  135. if ($_POST["FirstName"] != "Lewis" || $_POST["SecondName"] != "Allen" || $_POST["Email"] != "lewis@lancs.ac.uk"|| $_POST["db_login"] != "scc_130"|| $_POST["db_pass"] != "golf-87-solo")
  136. {
  137. echo "Error. Login credentials not valid.";
  138. }
  139. else //if ALL of the login details are correct then allow the user to choose which database they want to connect to
  140. {
  141. echo "Welcome back Lewis.";
  142.  
  143. $dbUsername = $_POST["db_login"];
  144. $dbPassword = $_POST["db_pass"];
  145.  
  146. $DB_USER = $dbUsername;
  147. $DB_PASS = $dbPassword;
  148. $DB_HOST = 'localhost';
  149. $DB_NAME = 'scc_130';
  150.  
  151. try {
  152. $db=new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=utf8", $DB_USER, $DB_PASSWORD);
  153. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  154. }
  155. catch (PDOException $e){
  156. echo "You have entered incorrect login details";
  157. }
  158.  
  159. //mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error());
  160.  
  161. ?>
  162. <tr> <!-- CONTENT ROW -->
  163. <td bgcolor="Orange">&nbsp;</td>
  164. <td bgcolor="Yellow" align="center">
  165. <form name="databaseSelect" method="post">
  166. <input type="radio" name="db" value="company"> Company<br>
  167. <input type="radio" name="db" value="fruits"> Fruits<br>
  168. <input type="radio" name="db" value="population"> Population<br>
  169. <input type="submit" name="databaseSubmit" value="Submit" >
  170. </form>
  171. </td>
  172. <td width="10" bgcolor="Orange">&nbsp;</td>
  173. </tr>
  174. <?php
  175. }
  176. }
  177. ?>
  178.  
  179.  
  180.  
  181. <?php
  182.  
  183. if(isset($_REQUEST"databaseSubmit"))
  184. $selected_radio =$POST['db'];
  185. if($selected_radio=="company")
  186. {
  187.  
  188.  
  189. $username = $_POST["db_login"];
  190. $password = $_POST["db_pass"];
  191.  
  192. $DB_USER = $username;
  193. $DB_PASSWORD = $password;
  194. $DB_HOST = 'localhost';
  195. $DB_NAME = 'scc_130';
  196.  
  197. $db=new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=utf8", $DB_USER, $DB_PASSWORD); //connect to the database
  198. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //throw exceptions when an error occurs
  199.  
  200.  
  201. try{
  202. $query = "SELECT * FROM company";
  203. $statement =$db->quesry($query);
  204. ?>
  205. <table border =2>
  206. <th>Year</th>
  207. <th>Sales</th>
  208. <th>Expenses</th>
  209. <?php
  210.  
  211. while ($row =$statement ->fetch(PDO::FETCH_ASSOC)){
  212.  
  213.  
  214.  
  215. echo "<tr><td>$row[year]</td><td>$row[Sales]</td><td>$row[Expenses]</td></tr>";
  216.  
  217. }
  218. ?>
  219. </table>
  220. <?php
  221. } catch(PDException $e){
  222. $message ="<p> Something went wrong</p><p>" . $e->getMessage(). "</p>";
  223. }
  224.  
  225. }
  226. else if ($selected _radio == "fruits")
  227. {
  228.  
  229.  
  230. }
  231. }
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. ?>
  243.  
  244.  
  245.  
  246.  
  247.  
  248. </body>
  249.  
  250. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement