Advertisement
Guest User

Untitled

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