Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.78 KB | None | 0 0
  1. <!--  
  2. Name: Chelen Lopez
  3. Course: CNT 4714 - Fall 2016
  4. Assignment title: A Three-Tier Distributed Web-Based Application
  5. Using PHP and Apache
  6. Date: December 4, 2016
  7. -->
  8. <!doctype html>
  9.  
  10. <html lang = "en">
  11.  
  12. <html>
  13.     <body body background="background.jpg">
  14.     <div style ="color: white">
  15.    
  16.         <header role = "banner" >
  17.    
  18.             <center><h1> CNT 4714 - Project Five Database Client </h1></center>
  19.    
  20.         </header>
  21.    
  22.     <hr>
  23.        
  24.         <table>
  25.             <tr>
  26.                 <td valign="top">
  27.                 <?php
  28.                 extract( $_GET );
  29.                 $username = $_GET['username'];
  30.                 $password = $_GET['password'];
  31.                 ?>
  32.                
  33.                 <br>
  34.                 <center>
  35.                 Welcome back
  36.                 <br>
  37.                 <?php
  38.                 print($username);
  39.                 //print($password);
  40.                 ?>
  41.                 <form method="post" action="login.html" >
  42.                 <input type="submit" value="Logout">
  43.                 </form>
  44.  
  45.                 </td>
  46.                
  47.                 <td>
  48.                
  49.                    
  50. <?php
  51.        
  52.     require_once('login.php');
  53.    
  54.     extract( $_POST );  
  55.     $query = $_POST['query'];
  56.    
  57.     // Connect to MySQL
  58.     if ( !( $conn = mysqli_connect( "localhost",
  59.     $username, $password, "project5", 3310 ) ) )
  60.         die( "Could not connect to database" );
  61.    
  62.     if ( !( $result = mysqli_query($conn, $query ) ) )
  63.     {
  64.         echo '
  65.         <h3 style="align: center; color: orange; "> Major Error: </h3>
  66.        
  67.         ';
  68.        
  69.         print(mysqli_error($conn));
  70.        
  71.         echo '
  72.        
  73.         Please try again later.
  74.        
  75.         <br> <br> <form method="post" action="login.html" >
  76.                 <input type="submit" value="Return to Main Page">
  77.                 </form>
  78.                
  79.                 <br>
  80.         ';
  81.                
  82.         exit();
  83.     }
  84.  
  85.                      
  86.     if( isset ($_POST[SubmitQuery])) {
  87.        
  88.         echo '
  89.         <h3 style = "color: orange">
  90.         Query Results</h3>
  91.         <table border = "1" cellpadding = "3"
  92.          style = "background-color: white" >  
  93.         ';
  94.  
  95.         // fetch meta-data
  96.         $metadata = mysqli_fetch_fields( $result);
  97.         print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
  98.         for ($i=0; $i<count($metadata); $i++){
  99.             print("<td>");
  100.             printf("%s",$metadata[$i]->name);
  101.             print("</td>");
  102.         }
  103.         print("</tr>");
  104.  
  105.            // fetch each record in result set
  106.             for ( $counter = 0;
  107.                $row = mysqli_fetch_row( $result );
  108.                $counter++ ){
  109.  
  110.                // build table to display results
  111.                print( "<tr style = 'color: black'>" );
  112.  
  113.                foreach ( $row as $key => $value )
  114.                   print( "<td>$value</td>" );
  115.  
  116.                print( "</tr>" );
  117.             }
  118.            
  119.         echo '</table><br />Your search yielded <strong>';
  120.        
  121.         print( "$counter" );
  122.        
  123.         echo '
  124.         results.<br /><br /></strong>
  125.  
  126.         <form method="post" action="login.html" >
  127.         <input type="submit" value="Return to Main Page">
  128.         </form>
  129.         ';  
  130.     }
  131.     else if( isset ($_POST[SubmitUpdate]))
  132.     {
  133.         if ((strpos ($query, 'update') !== false) OR (strpos ($query, 'insert') !== false))
  134.         {
  135.             //echo 'Success: update or insert found<br>';
  136.             //echo 'Query: ' . $query . '<br>';
  137.            
  138.            
  139.             if(preg_match_all('/\d+/', $query, $numbers))
  140.                 $lastnum = end($numbers[0]);
  141.            
  142.             //echo 'Last number:' . $lastnum . '<br>';
  143.            
  144.             if(strpos ($query, 'quantity') !== false)
  145.             {
  146.                 $pos = (strpos($query, "quantity"));
  147.                 //echo " Strpos: $pos <br>";
  148.                
  149.                 $querySubString = substr($query, $pos + strlen("quantity"), 6);
  150.                
  151.                 echo 'After Quantity: ' . $querySubString . '<br>';
  152.                
  153.                 if(preg_match_all('/\d+/', $querySubString, $strArr))
  154.                     $lastvalue = end($strArr[0]);
  155.                
  156.                 echo 'Last number:' . $lastvalue . '<br>';
  157.            
  158.             }
  159.            
  160.             if ($lastnum >= 100 || $lastvalue >= 100)
  161.             {
  162.                 $sql =  "
  163.                         UPDATE suppliers
  164.                         SET status = status + 5
  165.                         WHERE snum in (SELECT snum FROM shipments WHERE quantity > 100)
  166.                         ";
  167.                        
  168.                 if ($conn->query($sql) == TRUE)
  169.                 {
  170.                     $result = mysqli_query($conn, 'select * from suppliers' );
  171.                    
  172.                     echo '
  173.                         <SCRIPT LANGUAGE="JavaScript1.1">window.alert(
  174.  
  175.                         "ALERT: SUPPLIER STATUS HAS CHANGED DUE TO BUSINESS LOGIC. DISPLAYING UPDATED SUPPLIER TABLE!");
  176.  
  177.                         </SCRIPT>
  178.                         ';
  179.                    
  180.                     echo '
  181.                         <h3 style = "color: orange">
  182.                         Business Logic Modification to Supplies Table - Results</h3>
  183.                         <table border = "1" cellpadding = "3"
  184.                          style = "background-color: white" >  
  185.                         ';
  186.  
  187.                         // fetch meta-data
  188.                         $metadata = mysqli_fetch_fields( $result);
  189.                         print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
  190.                         for ($i=0; $i<count($metadata); $i++){
  191.                             print("<td>");
  192.                             printf("%s",$metadata[$i]->name);
  193.                             print("</td>");
  194.                         }
  195.                         print("</tr>");
  196.  
  197.                            // fetch each record in result set
  198.                             for ( $counter = 0;
  199.                                $row = mysqli_fetch_row( $result );
  200.                                $counter++ ){
  201.  
  202.                                // build table to display results
  203.                                print( "<tr style = 'color: black'>" );
  204.  
  205.                                foreach ( $row as $key => $value )
  206.                                   print( "<td>$value</td>" );
  207.  
  208.                                print( "</tr>" );
  209.                             }
  210.                            
  211.                         echo '</table><br />Your search yielded <strong>';
  212.                        
  213.                         print( "$counter" );
  214.                        
  215.                         echo '
  216.                         results.<br /><br /></strong>
  217.  
  218.                         <form method="post" action="login.html" >
  219.                         <input type="submit" value="Return to Main Page">
  220.                         </form>
  221.                         ';  
  222.                    
  223.                     //echo "Records updated successfully"  . '<br>';
  224.                 }
  225.                
  226.                 else
  227.                 {
  228.                     echo "Error updating record: " . $conn->error . '<br>';
  229.                 }
  230.                    
  231.             }
  232.             else
  233.             {
  234.                     echo '
  235.                            
  236.                         <b>Database Updated!</b>
  237.                         <br>
  238.                         <br>
  239.                            
  240.                         <form method="post" action="login.html" >
  241.                         <input type="submit" value="Return to Main Page">
  242.                         </form>
  243.                         ';  
  244.             }
  245.         }
  246.        
  247.     }
  248. ?>   
  249.                 </td>
  250.             <tr>
  251.         </table>
  252.     </center>
  253.    
  254.  
  255.    
  256.     <hr>
  257.        
  258.  
  259.     </div>
  260.     </body>
  261.    
  262.     <footer style="color:blue">
  263.         <br>
  264.         <br>
  265.         <center><div>&copy; CL CNT 4714 PHP - Based Database Client </div></center>
  266.        
  267.    
  268.     </footer>
  269.    
  270. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement