Jump to content
php.lv forumi

Errors: Undefined variable: searchterm


Ēriks Rudzītis

Recommended Posts

Sveiki!

Man nestrādā standarta grāmatas skripts!Kāpēc man rāda undefined variable??? Man register_globals ir ON!

 

HTML fails strādā ok...

 

"SEARCH.HTML"

 

<html>

<head>

<title>Book-O-Rama Catalog Search</title>

</head>

 

<body>

<h1>Book-O-Rama Catalog Search</h1>

 

<form action="results.php" method="post">

Choose Search Type:<br>

<select name="searchtype">

<option value="author">Author

<option value="title">Title

<option value="isbn">ISBN

</select>

<br>

Enter Search Term:<br>

<input name="searchterm" type="text">

<br>

<input type=submit value="Search">

</form>

 

</body>

</html>

 

Toties php failam rāda to UNDEFINED VARIABLE

 

"RESULTS.PHP"

 

<html>

<head>

<title>Book-O-Rama Search Results</title>

</head>

<body>

<h1>Book-O-Rama Search Results</h1>

<?

 

trim($searchterm);

if ((!isset($searchtype)) || !(isset($searchterm)))

{

echo "You have not entered search details. Please go back and try

again.";

exit;

}

 

$searchtype = addslashes($searchtype);

$searchterm = addslashes($searchterm);

 

@ $db = mysql_pconnect("localhost", "bookorama", "bookorama");

 

if (!$db)

{

echo "Error: Could not connect to database. Please try again later.";

exit;

}

 

mysql_select_db("books");

$query = "select * from books where ".$searchtype." Like

'%".$searchterm."%'";

$result = mysql_query($query);

$num_results = mysql_num_rows($result);

 

echo "<p>Number of books found: ".$num_results."</p>";

 

for ($i=0; $i <$num_results; $i++)

{

$row = mysql_fetch_array($result);

echo "<p><strong>".($i+1).". Title: ";

echo htmlspecialchars( stripslashes($row["title"]));

echo "</strong><br>Author: ";

echo htmlspecialchars (stripslashes($row["author"]));

echo "<br>ISBN: ";

echo htmlspecialchars (stripslashes($row["isbn"]));

echo "<br>Price: ";

echo htmlspecialchars (stripslashes($row["price"]));

echo "</p>";

}

 

?>

 

</body>

</html>

 

 

LŪŪŪDZU PALĪDZIET!!!

Jau iepriekš paldies!

Link to comment
Share on other sites

×
×
  • Create New...