Gooday everyone! Today I am making a very simple search engine with the help from a few notes that I have read. Now, my problem is that I get 3 errors whenever I try to run it. I am starting to learn oop so please bear with me since I am very new at this.
1st would be why doesn't it recognize $title from the user-search1.php?
2nd would be Undefined property: PDOStatement::$num_rows from my oop code(codex.php). What part did I done wrong?
3rd error is Invalid argument supplied for foreach(). I have a same loop function in my other file. I follow its format and how it is used but it still give me this errror. Why?
Here are my codes.
codex.php
public function search($table, $title){
$q = "SELECT * FROM $table WHERE title like '%:title%'";
$stmt = $this->con->query($q);
$num_result = $stmt->num_rows;
if($num_result > 0){
while($rows =$stmt->fetchAll(PDO::FETCH_ASSOC)){
$this->data[]=$rows;
header ("Location: user-search1.php");
}
return $this->data;
}
}
user-search1.php
<?php
include_once "dbconnection.php";
include_once "../styles/header-menu-out-user.php";
function __autoload($class){
include_once("../main/".$class.".php");}
$code = new codex();
$res = $code->search("book_info", $title);
if(isset($_POST['submit'])){
echo "<table id=\"tablecolor\" class=\"echoname\" >";
echo "<th><b>ID</b></th>";
echo "<th><b>Title</b></th>";
echo "<th><b>Author</b></th>";
echo "<th><b>ISBN</b></th>";
echo "<th><b>Publisher</b></th>";
echo "<th><b>Language</b></th>";
echo "<th><b>Genre</b></th>";
echo "<th><b>Quantity</b></th>";
echo "<pre>";
foreach($res as $result)
{
echo "<tr>";
extract($result);
echo "<td>".$id."</td>";
echo "<td>".$title."</td>";
echo "<td>".$author."</td>";
echo "<td>".$isbn."</td>";
echo "<td>".$publisher."</td>";
echo "<td>".$language."</td>";
echo "<td>".$genre."</td>";
echo "<td><center>".$quantity."</center></td>";
echo "</tr>";
}
echo "</pre>";
echo "</table>";
}
?>
Thanks in advance for those who would hopefully help me. Godspeed!