I'm trying to make a search engine but when I upload this code to my website I get
ERROR 003: An unknown error occurred.
I went to phpmyadmin and typed the SQL in the SQL tab and I got the right results but when I uploaded it to my website it didn't work.
<?PHP
global $output;
if(isset($_POST['submit'])){
if(!empty($_POST)) {
//Connect to DB
$conn = new mysqli('localhost', 'username', 'password', 'search')or die('ERROR 001: Something went wrong while connecting to MySQL server.');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$search = $_POST['searchBar'];
$result = $conn->query('SELECT * FROM websites WHERE url LIKE "%$search%" OR title LIKE "%$search%"')or die('ERROR 002: Something is wrong with you SQL.');
if(!$result->num_rows == 0) {
while($row = $result->fetch_assoc()) {
$title = $row['title'];
$url = $row['url'];
$id = $row['id'];
$output .= '<a href="' . $url . '" target="_blank">' . $title . '</a><br><br>';
}
} else {
$output = 'ERROR 003: An unknown error occurred.';
}
}
}
?>
<?PHP
require('search.php');
?>
<!DOCTYPE HTML>
<HTML lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "description" content = "null">
<meta name = "author" content = "Adam Oates">
<meta name = "title" content = "Search Engine">
<title title = "Gigaboy Search Engine">
Gigaboy Search Engine
</title>
<link rel = "apple-touch-icon" href = "">
<link rel = "shortcut icon" href = "">
<link rel = "stylesheet" type = "text/css" href = "main.css">
<script type = "text/javascript" src = "http://code.jquery.com/jquery-2.1.4.js"></script>
<script type = "text/javascript" src = "main.js"></script>
</head>
<body>
<header>
</header>
<section id = "mainIndex">
<div align = "center">
<form action = "index.php" method = "post">
<input type = "text" name = "searchBar" placeholder = "Search the Web" autocomplete = "off">
<input type = "submit" name = "submit" value = "Search">
</form><br><br>
<?PHP echo $output; ?>
</div>
</section>
<footer>
</footer>
</body>
</HTML>