Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.37 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.             $int = filter_var ($query, FILTER_SANITIZE_NUMBER_INT);
  142.                
  143.             //echo 'Intval: ' . $int . '<br>';
  144.            
  145.             if(preg_match_all('/\d+/', $query, $numbers))
  146.                 $lastnum = end($numbers[0]);
  147.            
  148.             //echo 'Last number:' . $lastnum . '<br>';
  149.            
  150.             if(strpos ($query, 'quantity') !== false)
  151.             {
  152.                 $pos = (strpos($query, "quantity"));
  153.                 //echo " Strpos: $pos <br>";
  154.                
  155.                 $num = substr($query, $pos + strlen("quantity"), 6);
  156.                 //echo $num;
  157.                
  158.                 if(preg_match_all('/\d+/', $query, $numbers))
  159.                     $lastvalue = end($numbers[0]);
  160.                
  161.                 //echo 'Last number:' . $lastvalue . '<br>';
  162.                
  163.                 if ($lastvalue >= 100)
  164.                 {
  165.                     //echo 'Success: quantity >= 100 found' . '<br>';
  166.                    
  167.                     $sql =  "
  168.                             UPDATE suppliers
  169.                             SET status = status + 5
  170.                             WHERE snum in (SELECT snum FROM shipments WHERE quantity > 100)";
  171.                            
  172.                     if ($conn->query($sql) == TRUE)
  173.                     {
  174.                         $result = mysqli_query($conn, 'select * from suppliers' );
  175.                        
  176.                         echo '
  177.                             <SCRIPT LANGUAGE="JavaScript1.1">window.alert(
  178.  
  179.                             "ALERT: SUPPLIER STATUS HAS CHANGED DUE TO BUSINESS LOGIC. DISPLAYING UPDATED SUPPLIER TABLE!");
  180.  
  181.                             </SCRIPT>
  182.                             ';
  183.                        
  184.                         echo '
  185.                             <h3 style = "color: orange">
  186.                             Business Logic Modification to Supplies Table - Results</h3>
  187.                             <table border = "1" cellpadding = "3"
  188.                              style = "background-color: white" >  
  189.                             ';
  190.  
  191.                             // fetch meta-data
  192.                             $metadata = mysqli_fetch_fields( $result);
  193.                             print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
  194.                             for ($i=0; $i<count($metadata); $i++){
  195.                                 print("<td>");
  196.                                 printf("%s",$metadata[$i]->name);
  197.                                 print("</td>");
  198.                             }
  199.                             print("</tr>");
  200.  
  201.                                // fetch each record in result set
  202.                                 for ( $counter = 0;
  203.                                    $row = mysqli_fetch_row( $result );
  204.                                    $counter++ ){
  205.  
  206.                                    // build table to display results
  207.                                    print( "<tr style = 'color: black'>" );
  208.  
  209.                                    foreach ( $row as $key => $value )
  210.                                       print( "<td>$value</td>" );
  211.  
  212.                                    print( "</tr>" );
  213.                                 }
  214.                                
  215.                             echo '</table><br />Your search yielded <strong>';
  216.                            
  217.                             print( "$counter" );
  218.                            
  219.                             echo '
  220.                             results.<br /><br /></strong>
  221.  
  222.                             <form method="post" action="login.html" >
  223.                             <input type="submit" value="Return to Main Page">
  224.                             </form>
  225.                             ';  
  226.                        
  227.                         //echo "Records updated successfully"  . '<br>';
  228.                     }
  229.                    
  230.                     else
  231.                     {
  232.                         echo "Error updating record: " . $conn->error . '<br>';
  233.                     }
  234.                        
  235.                 }
  236.                 else
  237.                 {
  238.                         $result = mysqli_query($conn, 'select * from parts' );
  239.                        
  240.                         echo '
  241.                            
  242.                             <h3 style = "color: orange">
  243.                             Parts Table Displayed</h3>
  244.                             <table border = "1" cellpadding = "3"
  245.                              style = "background-color: white" >  
  246.                            
  247.                             <b>Database Updated!</b>
  248.                             <br>
  249.                             <br>';
  250.  
  251.                             // fetch meta-data
  252.                             $metadata = mysqli_fetch_fields( $result);
  253.                             print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
  254.                             for ($i=0; $i<count($metadata); $i++){
  255.                                 print("<td>");
  256.                                 printf("%s",$metadata[$i]->name);
  257.                                 print("</td>");
  258.                             }
  259.                             print("</tr>");
  260.  
  261.                                // fetch each record in result set
  262.                                 for ( $counter = 0;
  263.                                    $row = mysqli_fetch_row( $result );
  264.                                    $counter++ ){
  265.  
  266.                                    // build table to display results
  267.                                    print( "<tr style = 'color: black'>" );
  268.  
  269.                                    foreach ( $row as $key => $value )
  270.                                       print( "<td>$value</td>" );
  271.  
  272.                                    print( "</tr>" );
  273.                                 }
  274.                                
  275.                             echo '</table><br />Your search yielded <strong>';
  276.                            
  277.                             print( "$counter" );
  278.                            
  279.                             echo '
  280.                             results.<br /><br /></strong>
  281.  
  282.                             <form method="post" action="login.html" >
  283.                             <input type="submit" value="Return to Main Page">
  284.                             </form>
  285.                             ';  
  286.                 }
  287.                    
  288.                    
  289.             }
  290.            
  291.             else if ($lastnum >= 100)
  292.             {
  293.                 //echo 'Success: quantity >= 100 found' . '<br>';
  294.                
  295.                 $sql =  "
  296.                         UPDATE suppliers
  297.                         SET status = status + 5
  298.                         WHERE snum in (SELECT snum FROM shipments WHERE quantity > 100)";
  299.                        
  300.                 if ($conn->query($sql) == TRUE)
  301.                 {
  302.                     $result = mysqli_query($conn, 'select * from suppliers' );
  303.                    
  304.                     echo '
  305.                         <SCRIPT LANGUAGE="JavaScript1.1">window.alert(
  306.  
  307.                         "ALERT: SUPPLIER STATUS HAS CHANGED DUE TO BUSINESS LOGIC. DISPLAYING UPDATED SUPPLIER TABLE!");
  308.  
  309.                         </SCRIPT>
  310.                         ';
  311.                    
  312.                     echo '
  313.                         <h3 style = "color: orange">
  314.                         Business Logic Modification to Supplies Table - Results</h3>
  315.                         <table border = "1" cellpadding = "3"
  316.                          style = "background-color: white" >  
  317.                         ';
  318.  
  319.                         // fetch meta-data
  320.                         $metadata = mysqli_fetch_fields( $result);
  321.                         print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
  322.                         for ($i=0; $i<count($metadata); $i++){
  323.                             print("<td>");
  324.                             printf("%s",$metadata[$i]->name);
  325.                             print("</td>");
  326.                         }
  327.                         print("</tr>");
  328.  
  329.                            // fetch each record in result set
  330.                             for ( $counter = 0;
  331.                                $row = mysqli_fetch_row( $result );
  332.                                $counter++ ){
  333.  
  334.                                // build table to display results
  335.                                print( "<tr style = 'color: black'>" );
  336.  
  337.                                foreach ( $row as $key => $value )
  338.                                   print( "<td>$value</td>" );
  339.  
  340.                                print( "</tr>" );
  341.                             }
  342.                            
  343.                         echo '</table><br />Your search yielded <strong>';
  344.                        
  345.                         print( "$counter" );
  346.                        
  347.                         echo '
  348.                         results.<br /><br /></strong>
  349.  
  350.                         <form method="post" action="login.html" >
  351.                         <input type="submit" value="Return to Main Page">
  352.                         </form>
  353.                         ';  
  354.                    
  355.                     //echo "Records updated successfully"  . '<br>';
  356.                 }
  357.                
  358.                 else
  359.                 {
  360.                     echo "Error updating record: " . $conn->error . '<br>';
  361.                 }
  362.                    
  363.             }
  364.             else
  365.             {
  366.                     $result = mysqli_query($conn, 'select * from parts' );
  367.                    
  368.                     echo '
  369.                        
  370.                         <h3 style = "color: orange">
  371.                         Parts Table Displayed</h3>
  372.                         <table border = "1" cellpadding = "3"
  373.                          style = "background-color: white" >  
  374.                        
  375.                         <b>Database Updated!</b>
  376.                         <br>
  377.                         <br>';
  378.  
  379.                         // fetch meta-data
  380.                         $metadata = mysqli_fetch_fields( $result);
  381.                         print("<tr style = 'background-color: white; color: blue; font-weight: bold; text-align:center'>");
  382.                         for ($i=0; $i<count($metadata); $i++){
  383.                             print("<td>");
  384.                             printf("%s",$metadata[$i]->name);
  385.                             print("</td>");
  386.                         }
  387.                         print("</tr>");
  388.  
  389.                            // fetch each record in result set
  390.                             for ( $counter = 0;
  391.                                $row = mysqli_fetch_row( $result );
  392.                                $counter++ ){
  393.  
  394.                                // build table to display results
  395.                                print( "<tr style = 'color: black'>" );
  396.  
  397.                                foreach ( $row as $key => $value )
  398.                                   print( "<td>$value</td>" );
  399.  
  400.                                print( "</tr>" );
  401.                             }
  402.                            
  403.                         echo '</table><br />Your search yielded <strong>';
  404.                        
  405.                         print( "$counter" );
  406.                        
  407.                         echo '
  408.                         results.<br /><br /></strong>
  409.  
  410.                         <form method="post" action="login.html" >
  411.                         <input type="submit" value="Return to Main Page">
  412.                         </form>
  413.                         ';  
  414.             }
  415.         }
  416.        
  417.     }
  418. ?>   
  419.                 </td>
  420.             <tr>
  421.         </table>
  422.     </center>
  423.    
  424.  
  425.    
  426.     <hr>
  427.        
  428.  
  429.     </div>
  430.     </body>
  431.    
  432.     <footer style="color:blue">
  433.         <br>
  434.         <br>
  435.         <center><div>&copy; CL CNT 4714 PHP - Based Database Client </div></center>
  436.        
  437.    
  438.     </footer>
  439.    
  440. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement