Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connect to DB
- $servername = "";
- $username = "";
- $password = "";
- $dbname = "";
- // Create connection
- $conn = new MySQLi($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Collect Data
- // Ensure user input string only has letter characters
- // Unimportant to current problem
- if(isset($_POST["aSearch"])) {
- $searchq = $_POST["aSearch"];
- $searchq = preg_replace("#[^0-9a-z]#i","",$searchq); //Can only search words
- // Select records which match the user's input
- $sql = "SELECT * FROM birdt WHERE birdName LIKE '%$searchq%'";
- }
- // Tests if the code been inserted
- if ($conn->query($sql)=== TRUE){
- echo "The rows you have searched for are:";
- } else {
- echo "Connection failed: ";
- echo $conn->error;
- }
- // Show fields
- $result = $conn->query($sql);
- // Output data of each row
- if ($result-> num_rows> 0) {
- readfile("ViewReturn.html"); // Returns the file in an HTML Page
- while($row = $result-> fetch_assoc()) {
- // echo "ID: ".$row["id"]. "<br>";
- echo "Bird Name: ".$row["birdName"]. "<br><br>";
- }
- } else {
- echo "0 results";
- }
- // Close connections
- if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
- echo "There was an error with MySQLi";
- } else {
- echo "Closing Connections";
- }
- $conn-> close();
- exit();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement