PDA

View Full Version : Scrip problem


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>

Galdo
09-04-2002, 06:00 PM
Why don't you move the trim($searchterm); into the section where you know that $searchterm actually has a value. In it's current position if someone hasnt entered something in the search then you will get that error.

Put it above the following line:

mysql_select_db("itohideo");

0810
09-04-2002, 09:20 PM
I moved trim($searchterm) above mysql_select_db("itohideo");

but it is not working yet.

Do you have any idea????


Galdo Thanks

Galdo
09-04-2002, 10:13 PM
You might need to use $_GET['searchterm'] or $_POST['searchterm'] depending on how you receive the searchterm variable (if PHP is configured so that you have to do this instead of only using $searchterm).

0810
09-04-2002, 10:21 PM
I actually add like this

$searchterm=$_POST["searchterm"];
$searchtype=$_POST["searchtype"];

under the


$searchtype = addcslashes($searchtype);
$searchterm = addcslashes($searchterm);

but still it doesn't work at all.

Dl you have any idea ???

Thanks all