Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Yahoo Answers: http://answers.yahoo.com/question/index?qid=20130614195000AAV5Uey
- <form action="show.php" method="post">
- <input type="text" value="Enter Site ID" name="a" class="textfield_effect" maxlength="30" onfocus="this.value=''">
- </td>
- </tr>
- <tr>
- <td align="center" style="font-family:Calibri">
- <input type="submit" value=""/>
- </form>
- <?php
- echo "<table border='1'>
- <tr>
- <th>ID</th>
- <th>Post Code</th>
- <th>Taxi Name</th>
- <th>Price per mile</th>
- <th>Rating</th>
- <th>Location</th>
- <th>Are they online?</th>
- <th>Are they busy?</th>
- </tr>" . PHP_EOL;
- if( $_SERVER['REQUEST_METHOD'] === 'POST'){
- $con = mysqli_connect("mysql.crunkboxhost.com","CHANGED","CHANGED","CHANGED");
- // Check connection
- if (mysqli_connect_errno()) {
- echo '<tr><td colspan="8">Failed to connect to MySQL: </td></tr><tr><td colspan="8">' . mysqli_connect_error($con) . '</td></tr>';
- }else{
- $a = mysqli_real_escape_string( trim( $_POST["a"] ) ); // SQL Injection protection (Not Best, but better than nothing)
- $result = mysqli_query($con,"SELECT * FROM datasearch WHERE TAXINAME LIKE '%$a%' LIMIT 0,30"); // Don't forget the wildcards
- if( !$result ){ // Malformed Query Statement
- echo '<tr><td colspan="8">Internal Error: </td></tr><tr><td colspan="8">' . mysqli_error($con) . '</td></tr>';
- }else if( $result->num_rows === 0){ // No Rows Returned / Not matches
- echo '<tr><td colspan="8">No results found for "' . $a . '".</td></tr>';
- }else{ // Matches
- // $query = "SELECT * FROM datasearch WHERE ID LIKE '%".$_POST['search']."%'"; // No IDEA what this is trying to accomplish, unless it's some attempt at a caching system
- while($row = mysqli_fetch_assoc($result)) {
- echo "<tr>";
- echo "<td>" . $row['ID'] . "</td>";
- echo "<td>" . $row['POSTCODE'] . "</td>";
- echo "<td>" . $row['TAXINAME'] . "</td>";
- echo "<td>" . $row['PRICEPERMILE'] . "</td>";
- echo "<td>" . $row['RATING'] . "</td>";
- echo "<td>" . $row['LOCATION'] . "</td>";
- echo "<td>" . $row['ONLINE'] . "</td>";
- echo "<td>" . $row['BUSY'] . "</td>";
- echo "</tr>";
- }
- }
- }
- if( is_resource($con) ){
- mysqli_close($con);
- }
- }else{
- echo '<tr><td colspan="8">Please Enter Site ID to search.</td></tr>';
- }
- echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement