Why my code is not working ?

Posts
23
Registration date
Sunday February 17, 2019
Status
Member
Last seen
March 2, 2019
-
When I type and serch for a word that exist in database table it says : "word not found"
Is there somthing I can do to fix this difunction ?
Thank you

<?php
$con=mysqli_connect("localhost","root","","dic") or die(mysql_error());
$output = '';

//collect
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "",$searchq);

$query = mysqli_query($con,"SELECT * FROM dictable WHERE word LIKE '%searchq%'") or die("could not search");
$count = mysqli_num_rows($query);
if ($count == 0) {
$output = 'Word not found !';
}else {

while($row = mysqli_fetch_array($query)) {
$word = $row['word'];
$definition = $row['definition'];
$id = $row['id'];

$output .= '<div>'.$word.' '.$definition.'</div>';

}

}
}

?>
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
</head>
<body>
<form action="dictionaryphpmysql.php" method="post">
<input type="text" name="search" placeholder="search for a word"/>
<input type="submit" value=">>"/>

</form>

<?php print("$output"); ?>
</body>
</html>
See more