0810
09-04-2002, 04:42 PM
hi how are you doing? I try to run this script but it doesn't work. what I am doing is that if a user resarches about books, it comes out info from my database.
my php editor says"Notice: Undefined variable: searchterm in c:\itohideo\results.php on line 7
Notice: Undefined variable: searchtype in c:\itohideo\results.php on line 8
you have not entered search details. Please go back and try again."
could you help me with it.
my php is 4.2
Thanks
here is code
<html>
<head></head>
<body>
<?php
trim($searchterm);
if(!$searchtype || !$searchterm)
{
echo"you have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addcslashes($searchtype);
$searchterm = addcslashes($searchterm);
@ $db = mysql_pconnect("localhost","itohideo","1234");
if(!$db){
echo"Error: Could not connet to dateabse. Please try again later.";
exit;
}
mysql_select_db("itohideo");
$sql="select * from books where".$searchtype." like '%".$searchterm."%'";
$result=mysql_query($sql);
$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["atthor"]));
echo"<br>ISBN: ";
echo htmlspecialchars( stripslashes($row["isbn"]));
echo"<br>Price: ";
echo htmlspecialchars( stripslashes($row["price"]));
echo "</p>";
}
?>
</body>
</html>
my php editor says"Notice: Undefined variable: searchterm in c:\itohideo\results.php on line 7
Notice: Undefined variable: searchtype in c:\itohideo\results.php on line 8
you have not entered search details. Please go back and try again."
could you help me with it.
my php is 4.2
Thanks
here is code
<html>
<head></head>
<body>
<?php
trim($searchterm);
if(!$searchtype || !$searchterm)
{
echo"you have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addcslashes($searchtype);
$searchterm = addcslashes($searchterm);
@ $db = mysql_pconnect("localhost","itohideo","1234");
if(!$db){
echo"Error: Could not connet to dateabse. Please try again later.";
exit;
}
mysql_select_db("itohideo");
$sql="select * from books where".$searchtype." like '%".$searchterm."%'";
$result=mysql_query($sql);
$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["atthor"]));
echo"<br>ISBN: ";
echo htmlspecialchars( stripslashes($row["isbn"]));
echo"<br>Price: ";
echo htmlspecialchars( stripslashes($row["price"]));
echo "</p>";
}
?>
</body>
</html>