Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--
- Name: Chelen Lopez
- Course: CNT 4714 - Fall 2016
- Assignment title: A Three-Tier Distributed Web-Based Application
- Using PHP and Apache
- Date: December 4, 2016
- -->
- <!doctype html>
- <html lang = "en">
- <html>
- <body body background="background.jpg">
- <div style ="color: white">
- <header role = "banner" >
- <center><h1> CNT 4714 - Project Five Database Client </h1></center>
- </header>
- <hr>
- <table>
- <tr>
- <td valign="top">
- <?php
- extract( $_GET );
- $username = $_GET['username'];
- $password = $_GET['password'];
- ?>
- <br>
- <center>
- Welcome back
- <br>
- <?php
- print($username);
- //print($password);
- ?>
- <form method="post" action="login.html" >
- <input type="submit" value="Logout">
- </form>
- </td>
- <td>
- <?php
- require_once('login.php');
- extract( $_POST );
- $query = $_POST['query'];
- // Connect to MySQL
- if ( !( $conn = mysqli_connect( "localhost",
- $username, $password, "project5", 3310 ) ) )
- die( "Could not connect to database" );
- if ( !( $result = mysqli_query($conn, $query ) ) )
- {
- echo '
- <h3 style="align: center; color: orange; "> Major Error: </h3>
- ';
- print(mysqli_error($conn));
- echo '
- Please try again later.
- <br> <br> <form method="post" action="login.html" >
- <input type="submit" value="Return to Main Page">
- </form>
- <br>
- ';
- exit();
- }
- if( isset ($_POST[SubmitQuery])) {
- echo '
- <h3 style = "color: orange">
- Query Results</h3>
- <table border = "1" cellpadding = "3"
- style = "background-color: white" >
- ';
- // fetch meta-data
- $metadata = mysqli_fetch_fields( $result);
- print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
- for ($i=0; $i<count($metadata); $i++){
- print("<td>");
- printf("%s",$metadata[$i]->name);
- print("</td>");
- }
- print("</tr>");
- // fetch each record in result set
- for ( $counter = 0;
- $row = mysqli_fetch_row( $result );
- $counter++ ){
- // build table to display results
- print( "<tr style = 'color: black'>" );
- foreach ( $row as $key => $value )
- print( "<td>$value</td>" );
- print( "</tr>" );
- }
- echo '</table><br />Your search yielded <strong>';
- print( "$counter" );
- echo '
- results.<br /><br /></strong>
- <form method="post" action="login.html" >
- <input type="submit" value="Return to Main Page">
- </form>
- ';
- }
- else if( isset ($_POST[SubmitUpdate]))
- {
- if ((strpos ($query, 'update') !== false) OR (strpos ($query, 'insert') !== false))
- {
- //echo 'Success: update or insert found<br>';
- //echo 'Query: ' . $query . '<br>';
- if(preg_match_all('/\d+/', $query, $numbers))
- $lastnum = end($numbers[0]);
- //echo 'Last number:' . $lastnum . '<br>';
- if(strpos ($query, 'quantity') !== false)
- {
- $pos = (strpos($query, "quantity"));
- //echo " Strpos: $pos <br>";
- $querySubString = substr($query, $pos + strlen("quantity"), 6);
- echo 'After Quantity: ' . $querySubString . '<br>';
- if(preg_match_all('/\d+/', $query, $querySubString))
- $lastvalue = end($querySubString[0]);
- echo 'Last number:' . $lastvalue . '<br>';
- }
- if ($lastnum >= 100 || $lastvalue >= 100)
- {
- $sql = "
- UPDATE suppliers
- SET status = status + 5
- WHERE snum in (SELECT snum FROM shipments WHERE quantity > 1000)
- ";
- if ($conn->query($sql) == TRUE)
- {
- $result = mysqli_query($conn, 'select * from suppliers' );
- echo '
- <SCRIPT LANGUAGE="JavaScript1.1">window.alert(
- "ALERT: SUPPLIER STATUS HAS CHANGED DUE TO BUSINESS LOGIC. DISPLAYING UPDATED SUPPLIER TABLE!");
- </SCRIPT>
- ';
- echo '
- <h3 style = "color: orange">
- Business Logic Modification to Supplies Table - Results</h3>
- <table border = "1" cellpadding = "3"
- style = "background-color: white" >
- ';
- // fetch meta-data
- $metadata = mysqli_fetch_fields( $result);
- print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
- for ($i=0; $i<count($metadata); $i++){
- print("<td>");
- printf("%s",$metadata[$i]->name);
- print("</td>");
- }
- print("</tr>");
- // fetch each record in result set
- for ( $counter = 0;
- $row = mysqli_fetch_row( $result );
- $counter++ ){
- // build table to display results
- print( "<tr style = 'color: black'>" );
- foreach ( $row as $key => $value )
- print( "<td>$value</td>" );
- print( "</tr>" );
- }
- echo '</table><br />Your search yielded <strong>';
- print( "$counter" );
- echo '
- results.<br /><br /></strong>
- <form method="post" action="login.html" >
- <input type="submit" value="Return to Main Page">
- </form>
- ';
- //echo "Records updated successfully" . '<br>';
- }
- else
- {
- echo "Error updating record: " . $conn->error . '<br>';
- }
- }
- else
- {
- echo '
- <b>Database Updated!</b>
- <br>
- <br>
- <form method="post" action="login.html" >
- <input type="submit" value="Return to Main Page">
- </form>
- ';
- }
- }
- }
- ?>
- </td>
- <tr>
- </table>
- </center>
- <hr>
- </div>
- </body>
- <footer style="color:blue">
- <br>
- <br>
- <center><div>© CL CNT 4714 PHP - Based Database Client </div></center>
- </footer>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement