Chiyembekezo Posted April 6, 2014 Share Posted April 6, 2014 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 58Invalid 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/287565-problem-with-search-page/ Share on other sites More sharing options...
QuickOldCar Posted April 6, 2014 Share Posted April 6, 2014 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/287565-problem-with-search-page/#findComment-1475145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.