Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset=”UTF-8">
- <title>Week 24/25</title>
- </head>
- <body>
- Login:
- <br>
- <br>
- <form action="" method="get">
- First name:<br><input type="text" name="first_name"><br>
- Surname:<br><input type="text" name="last_name"><br>
- Email:<br><input type="text" name="email"><br><br>
- <input type="submit" name="register" value="Register">
- </form>
- <?php
- if(isset($_REQUEST['register'] ))
- {
- if(empty($_GET["first_name"]) || empty($_GET["last_name"]) || empty($_GET["email"]))
- {
- echo "Please complete all fields.";
- }
- else
- {
- if (!filter_var($_GET["email"], FILTER_VALIDATE_EMAIL) === false)
- {
- echo 'Thanks ', $_GET["first_name"], ' ', $_GET["last_name"], ' for registering ', $_GET["email"], ' with us.';
- }
- else
- {
- echo("Please enter a valid email address");
- }
- }
- }
- ?>
- <br>
- <br>
- Connect to MySQL Database:
- <br>
- <br>
- <form action="" method="get" autocomplete="on">
- Username:<br><input type="text" name="username" placeholder="scc_130"> scc_130<br>
- Password:<br><input type="password" name="password" placeholder="golf-87-solo"> golf-87-solo<br>
- Table:<br>
- <select name="table" align="center">
- <option value="blank">Select a table</option>
- <option value="population">Population</option>
- <option value="company">Company</option>
- <option value="fruit">Fruits</option>
- </select><br>
- View:<br>
- <select name="view" align="center">
- <option value="table">Table</option>
- <option value="chart">Google Chart</option>
- </select><br><br>
- <input type="submit" name="connect" value="Submit">
- <br>
- <br>
- </form>
- <?php
- if(isset($_REQUEST['connect'] ))
- {
- require_once('connect.php');
- if($_GET["view"] == 'table')
- {
- if($_GET["table"] == 'blank')
- {
- echo "Please select a table";
- }
- if($_GET["table"] == 'population')
- {
- try{
- $query = "SELECT city AS Cities, people AS Population FROM population ORDER BY people DESC";
- $statement = $db->query($query);
- echo "<table border='1'>
- <tr>
- <th>Cities</th>
- <th>Population</th>
- </tr>";
- while($row = $statement->fetch(PDO::FETCH_ASSOC))
- {
- echo "<tr>";
- echo "<td>" . $row['Cities'] . "</td>";
- echo "<td>" . $row['Population'] . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- catch(PDOException $e){
- $message = '<p>Something went wrong!</p><p>' . $e->getMessage(). '</p>';
- }
- }
- if($_GET["table"] == 'company')
- {
- try{
- $query = "SELECT Sales, Expenses, Year FROM company ORDER BY Year DESC";
- $statement = $db->query($query);
- echo "<table border='1'>
- <tr>
- <th>Sales</th>
- <th>Expenses</th>
- <th>Year</th>
- </tr>";
- while($row = $statement->fetch(PDO::FETCH_ASSOC))
- {
- echo "<tr>";
- echo "<td>" . $row['Sales'] . "</td>";
- echo "<td>" . $row['Expenses'] . "</td>";
- echo "<td>" . $row['Year'] . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- catch(PDOException $e){
- $message = '<p>Something went wrong!</p><p>' . $e->getMessage(). '</p>';
- }
- }
- if($_GET["table"] == 'fruit')
- {
- try{
- $query = "SELECT fruit_name AS Fruit, amount AS Quantity FROM fruits ORDER BY Fruit ASC";
- $statement = $db->query($query);
- echo "<table border='1'>
- <tr>
- <th>Fruit</th>
- <th>Quantity</th>
- </tr>";
- while($row = $statement->fetch(PDO::FETCH_ASSOC))
- {
- echo "<tr>";
- echo "<td>" . $row['Fruit'] . "</td>";
- echo "<td>" . $row['Quantity'] . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- catch(PDOException $e){
- $message = '<p>Something went wrong!</p><p>' . $e->getMessage(). '</p>';
- }
- }
- }
- if($_GET["view"] == 'chart')
- {
- if($_GET["table"] == 'blank')
- {
- echo "Please select a table<br>";
- }
- if($_GET["table"] == 'population')
- {
- function generateGoogleChart()
- {
- //Get the data from the database
- $query = "SELECT City, People FROM population";
- $result = $db->query($query);
- $table = array();
- $table['cols'] = array(
- array('label' => 'City', 'type' => 'string'),
- array('label' => 'People', 'type' => 'number')
- );
- $rows = array();
- while($r = mysql_fetch_assoc($sth)) {
- $temp = array();
- // the following line will be used to slice the Pie chart
- $temp[] = array('v' => (string) $r['City']);
- $temp[] = array('v' => (int) $r['people']);
- $rows[] = array('c' => $temp);
- }
- $table['rows'] = $rows;
- $jsonTable = json_encode($table);
- }
- }
- }
- }
- ?>
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
- <script type="text/javascript">
- google.load('visualization', '1.0', {'packages':['corechart']});
- google.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = new google.visualization.DataTable(<?=$jsonTable?>);
- var options = {
- 'width':400,
- 'height':400};
- var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
- chart.draw(data, options);
- }
- </script>
- <div id="chart_div"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement