Newb here. Ideally, my if statement should load so that it asks the user to enter a term to search the text file to see if there is a match or not, if there is a match it will return the match (i still have to work that out).
Currently the instructions contained in the final else statement of dictionary_search.php does not show (#line #37-#44/else statement). I placed an isset around the overall if statement (i also experimented with an 'empty statement) as I had an undefined index notice which I believe was due to the user not having entered a submitted search yet. If i remove the 'islet', i get an error that reads as' Undefined index: dTerm in dictionary_search.php on line 15'.
I've gone through my code and looked at the bracketing, etc. and I've not been able to determine the reason for the malfunction. I want the page to initially load with the 'Enter the term you would like to search for below....' showing.
I am testing on my local server(MAMP)
Below is the actual pasted code from my IDE (BBedit v10) a010 | | 216
<h3>Dictionary</h3>
<?php //make sure the user submitted
if(isset($_REQUEST['submit'])) {
$dTerm = $_POST['dTerm'];//Term = name of dictionary entry
//make sure a non-empty request was entered
if(!empty($dTerm)) {
//check if term is in list
if(chekListing($dTerm)) {
echo '
Definition of the term $dTerm:
$dTerm <!--how to display definition?-->
<br /><br />
<a href="dictionary_search.php">Search Again?</a>
';
$search = true;
} else {
echo '
<p>No matching results found</p>
<br /><br />
<a href="dictionary_search.php">Search Again?</a>
';
}
}else {
//Our beginning default state
echo '
<p>Entry the term you would like to search for below.</p>
<form action="dictionary_search.php" method="post">
<input type="text" name="dTerm"/>
<br />
<input type ="submit" name = "submit" value="Search Current Entries"/>
</form>
<br /><br />
';
}
}
?>
<a href="dictionary_listings.php">Listings</a>
<a href="dictionary_contribute.php">Contribute</a>
</body>
</html>
Config File:
$title = "Dictionary";
define('FILE_NAME', 'dictionary.txt');//holds the file name
//Compares data entered against dictionary.txt file
function chekListing($dTerm) { //Term = name of dictionary entry
$fileName = "dictionary.txt";
$file = fopen($fileName, "r");
//loop through the file and compare to username
while(!feof($file)) {
$dItem = fgets($file);
$dItem = trim($dItem);//trim whitespace
$dTerm = trim($dTerm);
//converts both strings to lower case then compares
if(strtolower($dTerm) == strtolower($dItem)) {
fclose($file);
return true; }
}
fclose($file);
return false;
}