wolfkat
02-24-2003, 06:04 PM
I have got my PHP page to display info from a database (YAY!!!) and am impressed with the intuitive features I have found so far in PHP. I then tried to get a seach page together (simple one, just asking for a book ID or Name) and have the action.php file return the right information. But when I press the Submit button on my form, none of my $variables contain the search criteria entered in the form. I have included both the form and the php file code so if anyone more experienced and with less bloodshot eyes than me wants to take a crack at it, I would appreciate it. Again, thanks from a PHP/MYsql/General Linux newbie.
(PS, I am using a PHP/MySql book for help, but am still failing)
Ok, here is my form page:
<Html>
<Head>
<Title> RANW Member Search
</title>
</head>
<body>
<h1> Book Listing Search Page </h1>
<form action="action.php" method="post">
<select name="searchtype">
<option value="id">ID
<option value="name">Name
</select>
<br>
Enter Search Term:<br>
<input name="searchterm" type=text>
<br>
<input type=submit value="Search">
</form>
</body>
</html>
And here is my action.php page:
<Html>
<Head>
<Title = "Test">
</title>
</head>
<body>
<?php
trim($searchterm);
print $searchterm."<br>";
if(!$searchtype || !$searchterm)
{
echo "You Have Not Entered a Search Item. Please click BACK and try again";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
$db = mysql_pconnect("localhost", "userid", "somepass") or die("Not Connected: ".mysql_error());
mysql_select_db("IDX");
$query = "select * from Books where ".$searchtype." like '%".$searchterm."%'";
print $query;
$result = mysql_query($query) or die("Invalid Query: ".mysql_error());
$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["name"]));
echo "</strong><br>ID: ";
echo htmlspecialchars( stripslashes($row["id"]));
echo "</p>";
}
?>
PHP index page
</body>
</html>
(PS, I am using a PHP/MySql book for help, but am still failing)
Ok, here is my form page:
<Html>
<Head>
<Title> RANW Member Search
</title>
</head>
<body>
<h1> Book Listing Search Page </h1>
<form action="action.php" method="post">
<select name="searchtype">
<option value="id">ID
<option value="name">Name
</select>
<br>
Enter Search Term:<br>
<input name="searchterm" type=text>
<br>
<input type=submit value="Search">
</form>
</body>
</html>
And here is my action.php page:
<Html>
<Head>
<Title = "Test">
</title>
</head>
<body>
<?php
trim($searchterm);
print $searchterm."<br>";
if(!$searchtype || !$searchterm)
{
echo "You Have Not Entered a Search Item. Please click BACK and try again";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
$db = mysql_pconnect("localhost", "userid", "somepass") or die("Not Connected: ".mysql_error());
mysql_select_db("IDX");
$query = "select * from Books where ".$searchtype." like '%".$searchterm."%'";
print $query;
$result = mysql_query($query) or die("Invalid Query: ".mysql_error());
$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["name"]));
echo "</strong><br>ID: ";
echo htmlspecialchars( stripslashes($row["id"]));
echo "</p>";
}
?>
PHP index page
</body>
</html>