Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset=”UTF-8">
- <title>Page Title</title>
- </head>
- <body>
- <!--<form action="home.php" method="post">
- First name: <input type="text" name="FirstName"required><br>
- Second name: <input type="text" name= "SecondName"required><br>
- Email: <input type="text" name="Email"required><br>
- DB Login: <input type="text" name="db_login"required><br>
- DB Password:<input type="password" name="db_pass"required><br>
- <input type= "submit"> -->
- <table
- style="width:50%"
- align="center"
- border="4"
- cellspacing="4"
- cellpadding="8">
- <tr>
- <td width="100" rowspan="2" bgcolor="DeepSkyBlue">
- <img src="php.png" alt="PHP logo" width="100" height="75"/></td>
- <td width="*" align="center" bgcolor="DarkSeaGreen"><font
- color="MintCream" size="+2" face="Courier New"><strong>MY LINK
- PAGE</strong></font></td>
- <td width="100" rowspan="2" bgcolor="Red">
- <img src="mysql.png" alt=" MYSQL logo" width="100" height="75"/></td>
- </tr>
- <tr>
- <td bgcolor="LightSkyBlue">
- <table width="100%" border="1" cellspacing="2" cellpadding="2">
- <tr>
- <td width="50%" align="center" bgcolor="LightSeaGreen">
- <a href="main.php"> Home</a></td>
- <td width="50%" align="center" bgcolor="LightSeaGreen">
- <a href="ViewUsers.php"> View Users</a></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr> <!-- CONTENT ROW -->
- <td bgcolor="Orange"> </td>
- <td bgcolor="Yellow" align="center">
- <form action="home.php" method="post">
- First name: <input type="text" name="FirstName"required><br>
- Second name: <input type="text" name= "SecondName"required><br>
- Email: <input type="text" name="Email"required><br>
- DB Login: <input type="text" name="db_login"required><br>
- DB Password:<input type="password" name="db_pass"required><br>
- <input type= "submit" name "loginsubmit" value="submit">
- </form>
- </td>
- <td width="10" bgcolor="Orange"> </td>
- </tr>
- <!--<tr>
- <td bgcolor="Orange"> </td>
- <td bgcolor="Yellow" align="center">
- <p>
- what area would you like to see?
- <select name="form_table">
- <option value=""> Select...</option>
- <option value ="company">Company</option>
- <option value ="fruits">Fruits</option>
- <option value ="population">Population</option>
- </select>
- </p>
- </td>
- <td width="10" bgcolor="Orange"> </td>
- </tr>-->
- <?php
- $firstname = $_POST["FirstName"];
- $secondname = $_POST["SecondName"];
- if (!empty( $_POST["FirstName"])){
- if(!preg_match("/^[a-zA-Z ]*$/", $firstname)){
- echo " First name should only contain characters";
- }
- else if (!empty( $_POST["SecondName"])){
- if(!preg_match ("/^[a-zA-Z ]*$/", $secondname)){
- echo "Second name should only contain characters";
- }
- else{
- echo "hello ", $firstname ," ", $secondname, ".";
- }
- }else{
- echo "Second name has not been entered, please enter a name.";
- }
- } else{
- echo "First Name has not been entered, please enter a name.";
- }
- ?><br><br>
- <?php
- $email = $_POST["Email"];
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- echo "Email isn't in an email format.";
- }else{
- if (!empty($_POST["email"])) {
- echo "Your email is: " , $email;
- }else{
- //echo "Your email is: " , $email;
- //echo "Email has not been entered.";
- }
- }
- ?><br><br>
- <?php //when the login button is pressed
- if(isset($_REQUEST['loginsubmit'])) //request, contains the contents of get, post and cookie
- {
- if ($_POST["FirstName"] != "Lewis" || $_POST["SecondName"] != "Allen" || $_POST["Email"] != "lewis@lancs.ac.uk"|| $_POST["db_login"] != "scc_130"|| $_POST["db_pass"] != "golf-87-solo")
- {
- echo "Error. Login credentials not valid.";
- }
- else //if ALL of the login details are correct then allow the user to choose which database they want to connect to
- {
- echo "Welcome back Lewis.";
- $dbUsername = $_POST["db_login"];
- $dbPassword = $_POST["db_pass"];
- $DB_USER = $dbUsername;
- $DB_PASS = $dbPassword;
- $DB_HOST = 'localhost';
- $DB_NAME = 'scc_130';
- try {
- $db=new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=utf8", $DB_USER, $DB_PASSWORD);
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch (PDOException $e){
- echo "You have entered incorrect login details";
- }
- //mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error());
- ?>
- <tr> <!-- CONTENT ROW -->
- <td bgcolor="Orange"> </td>
- <td bgcolor="Yellow" align="center">
- <form name="databaseSelect" method="post">
- <input type="radio" name="db" value="company"> Company<br>
- <input type="radio" name="db" value="fruits"> Fruits<br>
- <input type="radio" name="db" value="population"> Population<br>
- <input type="submit" name="databaseSubmit" value="Submit" >
- </form>
- </td>
- <td width="10" bgcolor="Orange"> </td>
- </tr>
- <?php
- }
- }
- ?>
- <?php
- if(isset($_REQUEST"databaseSubmit"))
- $selected_radio =$POST['db'];
- if($selected_radio=="company")
- {
- $username = $_POST["db_login"];
- $password = $_POST["db_pass"];
- $DB_USER = $username;
- $DB_PASSWORD = $password;
- $DB_HOST = 'localhost';
- $DB_NAME = 'scc_130';
- $db=new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=utf8", $DB_USER, $DB_PASSWORD); //connect to the database
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //throw exceptions when an error occurs
- try{
- $query = "SELECT * FROM company";
- $statement =$db->quesry($query);
- ?>
- <table border =2>
- <th>Year</th>
- <th>Sales</th>
- <th>Expenses</th>
- <?php
- while ($row =$statement ->fetch(PDO::FETCH_ASSOC)){
- echo "<tr><td>$row[year]</td><td>$row[Sales]</td><td>$row[Expenses]</td></tr>";
- }
- ?>
- </table>
- <?php
- } catch(PDException $e){
- $message ="<p> Something went wrong</p><p>" . $e->getMessage(). "</p>";
- }
- }
- else if ($selected _radio == "fruits")
- {
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement