Advertisement
wunude0011

PHP table

Apr 2nd, 2020
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.31 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <title>0807_Login_Validation</title>
  4.  
  5.  
  6. </head>
  7.  
  8. <body style="font-family: Arial, Helvetica, sans-serif; color: Blue; background-color:">
  9.  
  10.  
  11. <form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
  12.  
  13.  
  14. <h2 style="background-color: #F5DEB3;">Login Validation</h2>
  15.  
  16.  
  17. <?php
  18. //*****************************************************
  19. //*
  20. //* Get Userid and password
  21. //*
  22. //*****************************************************
  23.  
  24. if (isset($_POST['userid']))
  25. {
  26.     $userid = $_POST['userid'];
  27. } else {
  28.     $userid = '';
  29.  
  30. }
  31.  
  32. if (isset($_POST['password']))
  33. {
  34.     $password = $_POST['password'];
  35. } else {
  36.     $password = '';
  37.  
  38. }
  39.  
  40. if (isset($_POST['userid']))
  41. {
  42.     echo "<input type='hidden' name='userid' size='11' value='".$userid."' /><br />";
  43.     echo "<input type='hidden' name='password' size='11' value='".$password."' /><br />";
  44. } else {
  45.     echo "<h2> Enter valid user/Password to Login: </h2>";
  46.  
  47.     echo "<table> ";
  48.  
  49.     echo "<tr> ";
  50.     echo "<td>User ID</td><td><input type ='text' name='userid' size='11' /><br /> ";
  51.     echo "</tr>";
  52.  
  53.  
  54.     echo "<tr> ";
  55.     echo "<td>Password</td><td><input type='text' name='password' size='11' value='".$password."' /><br />";
  56.     echo "</tr> ";
  57.  
  58.     echo "</table> ";
  59.  
  60.     echo "<p><input type='submit' name='mysubmit' value='Login' /> ";
  61.  
  62.     echo "</form></body></html>";
  63.  
  64.     exit;
  65.  
  66.  
  67.   }
  68.  
  69. //********************************************************
  70. //*
  71. //* Connect to MYSQL and Database
  72. //**
  73. //********************************************************
  74.  
  75.  $db = mysqli_connect('localhost','root','', 'working');
  76.  
  77. if (!$db)
  78. {
  79.     echo "<h1>Unable to Connect to MYSQL</h1>";
  80.  
  81. }
  82.  
  83.  
  84. //*****************************************************
  85. //*
  86. //* SELECT from table and display results
  87. //*
  88. //*****************************************************
  89.  
  90.   $sql_statement = "SELECT userid ";
  91.   $sql_statement .= "FROM validusers ";
  92.   $sql_statement .= "WHERE userid = '".$userid."' ";
  93.   $sql_statement .= "AND password = '".$password."' ";
  94.  
  95.  
  96.   $result = mysqli_query($db, $sql_statement);
  97.  
  98.  
  99.  
  100.  $outputDisplay = "";
  101.  $myrowcount = 0;
  102.  
  103.  if (!$result) {
  104.     $outputDisplay .= "<p style='color: red;'>MySQL' NO: ".mysqli_errno($db)."<br>";
  105.     $outputDisplay .= "MySQL Error: ".mysqli_error($db)."<br>";
  106.     $outputDisplay .= "<br>SQL: ".$sql_statement."<br>";
  107.  } else {
  108.  
  109.     $numresults = mysqli_num_rows($result);
  110.  
  111.     if ($numresults == 0)
  112.     {
  113.  
  114.         $outputDisplay .= "Invalid Login <br /> ";
  115.         $outputDisplay .= "Please go BACK and try again ";
  116.     } else {
  117.         $outputDisplay .= doShowList($db);
  118.     }
  119.  
  120.  }
  121.  
  122.  
  123.  ?>
  124.  
  125.  <h2 size="4" style="background-color: #F5DEB3; color: #F5DEB3;" />
  126.  
  127.  <?php
  128.  echo $outputDisplay;
  129.  
  130.  ?>
  131. </form>
  132. </body>
  133. </html>
  134. <?php
  135. function doShowList($db)
  136. {
  137.     $sql_statement = "SELECT Microphone_Audio_Kits, Microphone_Equip_Condition, Camera_Kits, Camera_Equip_Condition, Lighting_Kits, Lighting_Equp_Condition, Monitors_TriPods_Extras, Monitors_TriPods_Extras_Condition  ";
  138.     $sql_statement .="FROM equipment ";
  139.     $sql_statement .= "ORDER BY Microphone_Audio_Kits ";
  140.  
  141.     $result = mysqli_query($db, $sql_statement);
  142.  
  143.     $outputDisplay = "";
  144.     $myrowcount = 0;
  145.  
  146.     if (!$result) {
  147.     $outputDisplay .= "<p style='color: red;'>MySQL' NO: ".mysqli_errno($db)."<br>";
  148.     $outputDisplay .= "MySQL Error: ".mysqli_error($db)."<br>";
  149.     $outputDisplay .= "<br>SQL: ".$sql_statement."<br>";
  150.  } else {
  151.  
  152.     $outputDisplay = "<h3>cameras</h3>\n";
  153.  
  154.     $outputDisplay .= '<table border=1 style="color: black;">';
  155.     $outputDisplay .= '<tr><th>Microphone_Audio_Kits</th><th>Microphone_Equip_Condition</th><th>Camera_Kits</th><th>Camera_Equip_Condition</th><th>Lighting_Kits</th><th>Lighting_Equp_Condition</th><th>Monitors_TriPods_Extras</th><th>Monitors_TriPods_Extras_Condition</th></tr>' ."\n";
  156.  
  157.    $numresults = mysqli_num_rows($result);
  158.    
  159.         for ($i = 0; $i < $numresults; $i++)
  160.         {
  161.         if (!($i % 2) == 0)
  162.         {
  163.             $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
  164.         }  else {
  165.             $outputDisplay .= "<tr style=\"background-color:\">";
  166.         }
  167.  
  168.          $row = mysqli_fetch_array($result);
  169.  
  170.          $Microphone_Audio_Kits = $row['Microphone_Audio_Kits'];
  171.          $Microphone_Equip_Condition = $row['Microphone_Equip_Condition'];
  172.          $Camera_Kits = $row['Camera_Kits'];
  173.          $Camera_Equip_Condition = $row['Camera_Equip_Condition'];
  174.          $Lighting_Kits = $row['Lighting_Kits'];
  175.          $Lighting_Equp_Condition = $row['Lighting_Equp_Condition'];
  176.          $Monitors_TriPods_Extras = $row['Monitors_TriPods_Extras'];
  177.          $Monitors_TriPods_Extras_Condition = $row['Monitors_TriPods_Extras_Condition'];
  178.  
  179.          
  180.           $outputDisplay .= "<td>".$Microphone_Audio_Kits."</td>";
  181.           $outputDisplay .= "<td>".$Microphone_Equip_Condition."</td>";
  182.           $outputDisplay .= "<td>".$Camera_Kits."</td>";
  183.           $outputDisplay .= "<td>".$Camera_Equip_Condition."</td>";
  184.           $outputDisplay .= "<td>".$Lighting_Kits."</td>";
  185.           $outputDisplay .= "<td>".$Lighting_Equp_Condition."</td>";
  186.           $outputDisplay .= "<td>".$Monitors_TriPods_Extras."</td>";
  187.           $outputDisplay .= "<td>".$Monitors_TriPods_Extras_Condition."</td>";
  188.  
  189.  
  190.  
  191.       }
  192.  
  193.        $outputDisplay .="</table>\n";
  194.  
  195.  
  196.  
  197.    }
  198.  
  199.  
  200.    return $outputDisplay;
  201.  
  202.   }
  203.   ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement