Jump to content

not sure where error is taking plac


webguync

Recommended Posts

I am trying to adapt a database search form from a tutorial I saw, and it's not working. I just get a blank white slate despite having

error_reporting(E_ALL);

 

at the top of the page. I was hoping someone might be able to spot anything obvious I might be missing.

 

Here is my code

<?php
error_reporting(E_ALL);
// include MySQL-processing classes

require_once 'mysql.php';

try{

// connect to MySQL

$db=new MySQL(array
('host'=>'localhost','user'=>'username','password'=>'password',
'database'=>'DBName'));

$searchterm=$db->escapeString($_GET['searchterm']);

$result=$db->query("SELECT last_name, first_name,employee_id,title,territory,districts FROM
Scores WHERE MATCH(last_name,first_name,employee_id,title,territory,districts) AGAINST
('$searchterm')");

if(!$result->countRows()){

echo '<div class="maincontainer"><h2>No results were found. Go
back and try a new search.</h2></div>'."n";

}

else{

// display search results

echo '<div class="maincontainer"><h2>Your search criteria
returned '.$result->countRows().' results.</h2>'."n";

while($row=$result->fetchRow()){

echo '<div class="rowcontainer"><p><strong>First Name:
</strong>'.$row['first_name'].'<p><p><strong>Last Name:
</strong>'.$row['last_name'].'</p><p><strong>Employee ID:
</strong>'.$row['employee_id'].'</p>
<p><strong>Title:
</strong>'.$row['title'].'</p>
<p><strong>Territory:
</strong>'.$row['territory'].'</p>
<p><strong>Districts:
</strong>'.$row['districts'].'</p>
</div>'."n";

}

}

echo '</div>';

}

catch(Exception $e){

echo $e->getMessage();

exit();

}

?>


 

and here is the included file mysql.php code

<?php

// define 'MySQL' class

class MySQL{

private $conId;

private $host;

private $user;

private $password;

private $database;

private $result;

const OPTIONS=4;

public function __construct($options=array()){

if(count($options)!=self::OPTIONS){

throw new Exception('Invalid number of connection parameters');

}

foreach($options as $parameter=>$value){

if(!$value){

throw new Exception('Invalid parameter '.$parameter);

}

$this->{$parameter}=$value;

}

$this->connectDB();

}

// connect to MySQL

private function connectDB(){

if(!$this->conId=mysql_connect($this->host,$this->user,$this-
>password)){

throw new Exception('Error connecting to the server');

}

if(!mysql_select_db($this->database,$this->conId)){

throw new Exception('Error selecting database');

}

}

// run query

public function query($query){

if(!$this->result=mysql_query($query,$this->conId)){

throw new Exception('Error performing query '.$query);

}

return new Result($this,$this->result);

}

public function escapeString($value){

return mysql_escape_string($value);

}

}

// define 'Result' class

class Result {

private $mysql;

private $result;

public function __construct(&$mysql,$result){

$this->mysql=&$mysql;

$this->result=$result;

}

// fetch row

public function fetchRow(){

return mysql_fetch_assoc($this->result);

}

// count rows

public function countRows(){

if(!$rows=mysql_num_rows($this->result)){

return false;

}

return $rows;

}

// count affected rows

public function countAffectedRows(){

if(!$rows=mysql_affected_rows($this->mysql->conId)){

throw new Exception('Error counting affected rows');

}

return $rows;

}

// get ID form last-inserted row

public function getInsertID(){

if(!$id=mysql_insert_id($this->mysql->conId)){

throw new Exception('Error getting ID');

}

return $id;

}

// seek row

public function seekRow($row=0){

if(!is_int($row)||$row<0){

throw new Exception('Invalid result set offset');

}

if(!mysql_data_seek($this->result,$row)){

throw new Exception('Error seeking data');

}

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/229615-not-sure-where-error-is-taking-plac/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.