Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>0802_Pass_Data_to_Select</title>
- </head>
- <body style="font-family: Arial, Helvetica, sans-serif; color: Blue; background-color:">
- <form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
- <h2> Pass Data to a select statement</h2>
- <p> Enter SSN Code to see by state:
- <input type='text' name='ssncode' size='2' />
- </p>
- <?php
- //*************************************************
- //*
- //* Get SSN Code
- //*
- //**************************************************
- if (isset($_POST['ssncode']))
- {
- $ssncode = $_POST['ssncode'];
- if (empty($ssncode))
- {
- $ssncode = 'ALL';
- }
- } else {
- $ssncode = 'ALL';
- }
- //******************************************
- //* Connect to MYSQL and Database
- //*
- //******************************************
- $db = mysqli_connect('localhost','root','', 'working');
- if (!$db)
- {
- echo "<h1>Unable to Connect to MySQL</h1>";
- }
- //********************************************
- //*
- //* SELECT from table and dislay Results
- //*
- //*********************************************
- $sql_statement = "SELECT Camera_Kits, Lighting_kits, Monitors_TriPods_Extras ";
- $sql_statement .= "FROM equipment ";
- if ($ssncode != 'ALL')
- {
- $sql_statement .= "WHERE Camera_Kits = '".$ssncode."' ";
- }
- $sql_statement .= "ORDER BY Camera_Kits ";
- $result = mysqli_query($db, $sql_statement); // Run SELECT
- $outputDisplay = "";
- $myrowcount = 0;
- if (!$result) {
- $outputDisplay .= "<p style='color: red;'>MYSQL No: ".mysqli_errno($db)."<br>";
- $outputDisplay .= "MYSQL Error: ".mysqli_error($db)."<br>";
- $outputDisplay .= "<br>SQL: ".$sql_statement."<br>";
- } else {
- if ($ssncode == 'ALL')
- {
- $outputDisplay = "<h3>SSN Codes for each person</h3>";
- } else{
- $outputDisplay = "<h3>SSN Codes for each person lives </h3>";
- }
- $outputDisplay .= '<table border=1 style="color: black;">';
- $outputDisplay .= '<tr><th>Camera_Kits</th><th>Lighting_kits</th><th>Monitors_TriPods_Extras</th></tr>';
- $numresults = mysqli_num_rows($result);
- for ($i = 0; $i < $numresults; $i++)
- {
- if (!($i % 2) == 0)
- {
- $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
- } else {
- $outputDisplay .= "<tr style=\"background-color: white; cellpadding: 10;\">";
- }
- $myrowcount++;
- $row = mysqli_fetch_array($result);
- $Camera_Kits = $row['Camera_Kits'];
- $Lighting_kits = $row['Lighting_kits'];
- $Monitors_TriPods_Extras = $row['Monitors_TriPods_Extras'];
- $outputDisplay .= "<td>".$Camera_Kits."</td>";
- $outputDisplay .= "<td>".$Lighting_kits."</td>";
- $outputDisplay .= "<td>".$Monitors_TriPods_Extras."</td>";
- $outputDisplay .= "</tr>";
- }
- $outputDisplay .= "</table>";
- }
- ?>
- <br /><br /><input type="submit" value="Submit SQL Statements" />
- <?php
- $outputDisplay .= "<br /><br /><b>Number of Rows in Results: $myrowcount </b><br /><br />";
- echo $outputDisplay;
- ?>
- </body>
- </form>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement