Advertisement
wunude0011

Untitled

Apr 8th, 2020
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>0802_Pass_Data_to_Select</title>
  4.  
  5. </head>
  6.  
  7. <body style="font-family: Arial, Helvetica, sans-serif; color: Blue; background-color:">
  8.   <link rel="stylesheet" type="text/css" href="basic1.css">
  9.  
  10. <form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. <h2> Pass Data to a select statement</h2>
  18.  
  19. <p> Enter SSN Code to see by state:
  20. <input type='text' name='ssncode' size='2' />
  21. </p>
  22.  
  23.  
  24. <?php
  25. //*************************************************
  26. //*
  27. //* Get SSN Code
  28. //*
  29. //**************************************************
  30.  
  31. if (isset($_POST['ssncode']))
  32. {
  33.     $ssncode = $_POST['ssncode'];
  34.  
  35.     if (empty($ssncode))
  36.     {
  37.        $ssncode = 'ALL';
  38.  
  39.     }
  40.  
  41.  } else {
  42.     $ssncode = 'ALL';
  43.  }
  44.  
  45.  
  46. //******************************************
  47. //* Connect to MYSQL and Database
  48. //*
  49. //******************************************
  50.  
  51.  $db = mysqli_connect('localhost','root','', 'working');
  52.  
  53.  if (!$db)
  54.  {
  55.  
  56.     echo "<h1>Unable to Connect to MySQL</h1>";
  57.  }
  58.  
  59.  
  60. //********************************************
  61. //*
  62. //*  SELECT from table and dislay Results
  63. //*
  64. //*********************************************
  65.  
  66.  $sql_statement = "SELECT lighting ";
  67.  $sql_statement .= "FROM lights ";
  68.  
  69.  
  70.  if ($ssncode != 'ALL')
  71.  {
  72.  
  73.     $sql_statement .= "WHERE lighting  = '".$ssncode."' ";
  74.  }
  75.  
  76.    $sql_statement .= "ORDER BY lighting ";
  77.  
  78.  $result = mysqli_query($db, $sql_statement); // Run SELECT
  79.  
  80.  $outputDisplay = "";
  81.  $myrowcount = 0;
  82.  
  83.  if (!$result) {
  84.     $outputDisplay .= "<p style='color: red;'>MYSQL No: ".mysqli_errno($db)."<br>";
  85.     $outputDisplay .= "MYSQL Error: ".mysqli_error($db)."<br>";
  86.     $outputDisplay .= "<br>SQL: ".$sql_statement."<br>";
  87. } else {
  88.  
  89.  
  90. if ($ssncode == 'ALL')
  91. {
  92.  
  93.     $outputDisplay = "<h3>SSN Codes for each person</h3>";
  94. }   else{
  95.  
  96.     $outputDisplay = "<h3>SSN Codes for each person lives </h3>";
  97.  
  98. }
  99.  
  100. $outputDisplay .= '<table border=1 style="color: black;">';
  101.  $outputDisplay .= '<tr><th>lighting<input type="checkbox" name="Aputure" value="Aputure">';
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  $numresults = mysqli_num_rows($result);
  108.  
  109.  
  110.     for ($i = 0; $i < $numresults; $i++)
  111.     {
  112.         if (!($i % 2) == 0)
  113.         {
  114.             $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
  115.         }  else {
  116.             $outputDisplay .= "<tr style=\"background-color: white; cellpadding: 10;\">";
  117.  
  118.         }
  119.        
  120.         $myrowcount++;
  121.  
  122.         $row = mysqli_fetch_array($result);
  123.  
  124.         $lighting = $row['lighting'];
  125.      
  126.  
  127.         $outputDisplay .= "<td>".$lighting."</td>";
  128.    
  129.  
  130.        
  131.       $outputDisplay .= "</tr>";
  132.  
  133.  
  134.        }
  135.    $outputDisplay .= "</table>";
  136.  
  137.  
  138.      }
  139.    
  140. if (isset ($_POST['Aputure']))
  141. {  
  142.    $Aputure  = $_POST['Aputure'];
  143.    } else {
  144.       $Aputure = "";
  145. }
  146.  
  147.  
  148. if (isset ($_POST['Bescore']))
  149. {  
  150.    $Bescore  = $_POST['Bescore'];
  151.    } else {
  152.       $Bescore = "";
  153. }
  154.  
  155. if (isset ($_POST['Dedo']))
  156. {  
  157.    $Dedo  = $_POST['Dedo'];
  158.    } else {
  159.       $Dedo = "";
  160. }
  161.  
  162. if (isset ($_POST['Halogen']))
  163. {  
  164.    $Halogen  = $_POST['Halogen'];
  165.    } else {
  166.       $Halogen = "";
  167. }
  168.  
  169. if (isset ($_POST['Keno']))
  170. {  
  171.    $Keno  = $_POST['Keno'];
  172.    } else {
  173.       $Keno = "";
  174. }
  175.  
  176. if (isset ($_POST['LightingKit1']))
  177. {  
  178.    $LightingKit1  = $_POST['LightingKit1'];
  179.    } else {
  180.       $LightingKit1 = "";
  181. }
  182.  
  183. if (isset ($_POST['LightingKit1']))
  184. {  
  185.    $LightingKit1  = $_POST['LightingKit1'];
  186.    } else {
  187.       $LightingKit1 = "";
  188. }
  189.  
  190. if (isset ($_POST['LightingKit2']))
  191. {  
  192.    $LightingKit2  = $_POST['LightingKit2'];
  193.    } else {
  194.       $LightingKit2 = "";
  195. }
  196.  
  197.  
  198. echo "<p><span class='textblue'>  $Aputure </span></p>";
  199. echo "<p><span class='textblue'>  $Bescore </span></p>";
  200. echo "<p><span class='textblue'>  $Dedo </span></p>";
  201. echo "<p><span class='textblue'>  $Halogen </span></p>";
  202. echo "<p><span class='textblue'>  $Keno </span></p>";
  203. echo "<p><span class='textblue'>  $LightingKit1 </span></p>";
  204. echo "<p><span class='textblue'>  $LightingKit2 </span></p>";
  205.  
  206.  
  207.  
  208.    ?>
  209.  
  210.  
  211.  <br /><br /><input type="submit" value="Submit SQL Statements" />
  212.  
  213.  <?php
  214.   $outputDisplay .= "<br /><br /><b>Number of Rows in Results: $myrowcount </b><br /><br />";
  215.   echo  $outputDisplay;
  216.   ?>
  217. </body>
  218.  
  219.  
  220.  
  221. </form>
  222. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement