miftari0 miftari0 - 17 days ago 6
PHP Question

Searh engine using url

Hey i started making site for songs. It is lyrics site and i wanted a search engine that works something like picture below.

It should works with URL.

Like this

anybody help?

<form action="#" method="POST">
<input type="text" name="search"/>
<input type="submit" name="submit" value="Submit">
</form>
<?php
require "connection-to.php";
$notFound = "";
$song = "";
if(isset($_POST['submit'])){
$search = mysqli_real_escape_string($conn, $_POST['search']);
$search = strtolower($search);
$sql = "SELECT * FROM `music` WHERE `name` = '" . $search . "'";
$query = mysqli_query($conn, $sql);
$numRows = mysqli_num_rows($query);
if($numRows != 0){
while($row = mysqli_fetch_array($query)){
echo $row['lyrics'] . "<br><br><br>";
}
} else {
echo $search . " Was Not Found.";
}
}
?>

Answer

You don't want send a POST request. Change

<form action="#" method="POST">

to

<form action="" method="GET">

Then you can retrive it with $_GET['search'] instead of $_POST['search'].