0

The purpose of my lab is to have the user search through a database called "pageVistis" from what they enter in the field. They can search through the remote host or page name. I have Been having trouble fixing an error that i am recieving saying "Notice: Undefined variable: searchtype in C:\xampp\htdocs\pageVisitsLab\DataBC.php on line 23

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\pageVisitsLab\DataBC.php:25 Stack trace: #0 {main} thrown in C:\xampp\htdocs\pageVisitsLab\DataBC.php on line 25". Also the code is form a file called "DataBC.php". If any extra information is needed please let me know and i will edit this post and include it thank you.

include "interface.php";
if(isset($_POST['submit'])) {

    $sName = $_POST['sN'];
    $sHost = trim($_POST['sH']);


  if(!$sName || ! $sHost) {
      echo "<p> Please enter a search </p>";
      exit;
  }
  /*switch ($sName) {
      case 'sName':
      case 'sHost':
          break;
      default:
          echo  "<p> Invalid search type and please try again </p>";
  }
 */

 $query = "SELECT page_name, visit_date, previous_page, request_method, remote_host, remote_port FROM visitInfo 
            WHERE $searchtype= ?";
   $stmt = $databse -> prepare($query);
   $stmt-> bind_param('s',$sName);
$stmt-> execute();
 $stmt->store_result();
  $stmt->bind_result($pageName,$visitDate,$previouPage,$requestMethod,$remoteHost,$remotePort);
  echo "<p> The number of items found: .$stmt->num_rows</p>";

  while ($stmt->fetch()) {
      echo  "<p><strong>page Name: ".$pageName."</strong></p>";
      echo "Visit Date: ".$visitDate."<br>";
      echo  "Previous Page: ".$previouPage. "<br>";
      echo  " Request Method: ".$requestMethod. "<br>";
      echo  "Remote Host: ".$remoteHost. "<br>";
      echo "Remote Port: ".$remotePort. "<br>";
  }
  $stmt->free_result();
  $databse->close();

 }
?>

1 Answers1

0

I think your problem is in your query, is $searchtype a variable you define in php? maybe in that interface.php.

If you want to use a php variable in a mysql query then that is not the correct way of doing it.

JoaoFRF
  • 25
  • 5