Jump to content

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');
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.