Jump to content

Problem with Search Page


Chiyembekezo

Recommended Posts

I have a search page that is working but is generating an error despite working. The error is 

 

Notice: Undefined index: var1 in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\my portable files\air\search.php on line 58
Invalid form value:

 

The code that i have is here below. The first line in the code below is the line 58

$var1 = str_replace(array('%','_'),'',$_POST['var1']);
if (!$var1)
{
    exit('Invalid form value: '.$var1);
}


$query = "SELECT * FROM holder WHERE Surname LIKE :search OR FirstName LIKE :search OR Variable Like :search OR Number Like :search GROUP BY holder.EmployeeID";
$statement = $db->prepare($query);
$statement->bindValue(':search', '%' . $var1 . '%', PDO::PARAM_INT);
echo "<table border='1' cellpadding='10'>";
        echo "<tr> <th>Surname</th> <th>First Name</th> <th>Rank</th> <th>Number</th></tr>";
$statement->execute();

/* Fetch all of the remaining rows in the result set */
print("Here are the results of your search Sir:\n");

$statement->setFetchMode(PDO::FETCH_ASSOC); // Set the fetch mode.



while ($row = $statement->fetch())
{
    $Surname = $row['Surname'];
    $FirstName = $row['FirstName'];
    $Variable = $row['Variable'];
	$Variable = $row['Number'];

  echo "<tr>";
                echo '<td>' . $row['Surname'] . '</td>';
                echo '<td>' . $row['FirstName'] . '</td>';
                echo '<td>' . $row['Variable'] . '</td>';
				echo '<td>' . $row['Number'] . '</td>';
				echo '<td><a href="details.php?EmployeeID=' . $row['EmployeeID'] . '">Details</a></td>';
Link to comment
https://forums.phpfreaks.com/topic/287565-problem-with-search-page/
Share on other sites

Check to see that the $_POST value is set and not blank first

 

 

if(isset($_POST['var1']) && trim($_POST['var1']) != ''){
$var1 = str_replace(array('%','_'),'',$_POST['var1']);
}

 

But also after you check for $var1 existing, you try and use it in your exit message

so don't use it

 

if (!$var1){
exit('Invalid form value');
}

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.