Hi I have a simple database called GamEco in which there is a table called Games that contains the following values:
(`Serial`,`Title`, `Price`,`Genre`,`Developer`,`Platform`,`Available`)
I inserted a game with PHP in a separate file and I tested finding it with query in searchtest.php:
<?php
require "connect_to_mysql.php";
$sql = 'SELECT * FROM `Games` WHERE `Developer`="Valve"';
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_assoc($result);
print_r($row);
?>
And it outputs correctly in browser with localhost/bootstrap/searchtest.php:
Array ( [Serial] => 1234 [Title] => Counter Strike: Global Offensive [Price] => 15 [Genre] => Shooter [Developer] => Valve [Platform] => PC [Available] => 5 )
Now I have a simple HTML website that asks the User for a searchtype and searchterm and PHP will process the inputs and get the row from the MySQL table. EDIT
<!DOCTYPE html>
<html>
<head>
<title>GamEco</title>
</head>
<body>
<form class="form-horizontal" target="blank" name="search" method="post" action="search.php">
Choose Search Type:<br>
<select name="searchtype">
<option value="title">Title</option>
<option value="genre">Genre</option>
<option value="developer">Developer</option>
</select> <br>
Enter Search Term: <br>
<p> <input name="searchterm" type="text" size=40>
<p> <input type="submit" value="Submit">
</form>
</body>
</html>
And this is my search.php file: EDIT3
<?php
error_reporting(E_ALL);
ini_set("display_errors",1);
//require "connect_to_mysql.php";
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$type=$_POST['searchtype'];
$term=$_POST['searchterm'];
/*
if($type == 'title'){
//get results that equal the term
$sql = 'SELECT * FROM `Games` where `Title` = ' . $term;
} else if ($type == 'genre'){
//get results that equal the term
$sql = 'SELECT * FROM `Games` where `Genre` = ' . $term;
} else if ($type == 'developer'){
//get results that equal the term
$sql = 'SELECT * FROM `Games` where `Developer` = ' . $term;
} else {
print_r("Could not find.");
}
*/
$sql = 'SELECT * FROM `Games` where `' . $type . '` = ' . $term;
$result = mysqli_query($conn,$sql);
$row = mysql_fetch_assoc($result);
print_r($row);
?>
But nothing happens. I'm sure it is something simple but I'm really new to PHP/HTML and I have to use it for my database project.
It is now leading me to another page which is progress here is the error I get:
Connected successfully
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\bootstrap\search.php on line 36