mardi 3 janvier 2017

PHP MySQL searching

I am looking to have a second field search the database for a column 'key_id'. I have done some searching but I keep finding articles on multiple inputs for one search which is not what I am looking for.

I would like to keep the Address / Name search and ass a second search looking for key_id.

This is not the final project and is internal only, I am aware of the security risk involved in this code.

Thank you!

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
    background-color: #767676;
}
</style>
<body bgcolor="grey" text="white">
<form method="POST" />
<h2>Please Enter Customer Address</h2><input type="text" name="search"/>
<input type="SUBMIT" name="submit" value="Search" />
</form>
</head>
</html>
<?php
$output = NULL;
if(isset($_POST['submit'])){
    //CONNECTION TO DATABASE
    $mysqli = NEW MySQLi ('localhost','root','','restrictedkeys');

    $search = $mysqli->real_escape_string($_POST['search']);


    //QUERY THE DATABASE

    $resultSet = $mysqli->query("SELECT * FROM restrictedkeys WHERE Address  LIKE '%$search%' OR Name LIKE '%$search'");
        if($resultSet->num_rows > 0){
            while ($rows = $resultSet->fetch_assoc())
            {

                $bitting = $rows['bitting'];
                $name = $rows['Name'];
                $cx = $rows['cx_id'];
                $address = $rows['Address'];
                $outer = $rows['outer_hand'];
                $install_date = $rows ['Installation_date'];
                $cab = $rows ['cabinet'];
                $auth1 = $rows ['SigningAuth_1'];
                $auth2 = $rows ['SigningAuth_2'];
                $auth3 = $rows ['SigningAuth_3'];
                $key = $rows ['key_mark']; 
                $chone_sidepin = $rows  ['ch1_Sidepin'];
                $chtwo_sidepin = $rows  ['ch2_Sidepin'];
                $chthree_sidepin = $rows  ['ch3_sidepin'];
                $chfour_sidepin = $rows  ['ch4_sidepin'];
                $chfive_sidepin = $rows ['ch5_sidepin'];
                $color = $rows ['color'];


                $output .= "

<style>
table{
    table-layout: fixed;
    width: 100%;
}
table, th, td {
    border: 1px solid black;
    text-align: center;




}
}
th, td {
    text-align: center;

}
th {
    text-align: center;
}
</style>
<table
    <tr>
        <th>Customer Name</th>
        <th>Customer Address</th>
        <th>Edit</th>


    </tr>
    <tr>
        <td>$name</td>
        <td>$address</td>
        <td><a href='edit.php?cx_id=" . $rows['cx_id']."'>Edit</a></td>




        ";


            }
        }else{
            $output = "No Results";
        }
}


?>




<?php echo $output; ?>




Aucun commentaire:

Enregistrer un commentaire