by 007 » Fri Mar 11, 2005 6:39 am
Or should I give the whole code?
_______________________
<html>
<head>
<title>Penpals</title>
</head>
<body>
<font face="verdana" size=1 color="purple">
<h4>Penpal Search</h4>
<?php
if (!$_REQUEST) {
html_form();
} else {
select_penpal();
}
function html_form() {
?>
<table>
<tr><td><font size=1><b>
<form name="search" method="post" action="<? echo $_SERVER; ?>">
Type of Penpal:</td><td> <select name="type">
<option>All
<option>female
<option>male
<option>Other
</select></td></tr>
<tr><td><font size=1><b>
Location:</td><td><select name="province">
<option>All
<option>Nairobi
<option>R-Valley
<option>Coast
<option>Central
<option>Eastern
<option>Nyanza
<option>Western
<option>North-Estern
<option>Uganda
<option>Tanzania
</select><br>
</td></tr><tr><td></td><td>
<input type="submit" name="Submit" value="Search">
</td></tr>
</form>
</table>
<?
}
function select_penpal() {
?>
<h4>Search Results</h4>
<?
/* set's the variables for MySQL connection */
$server = "127.0.0.1"; // this is the server address
/* $username = "username"; // change this to your username
$password = "password"; // change this to your password */
/* Connects to the MySQL server */
$link = @mysql_connect ($server)
or die (mysql_error());
/* Defines the Active Database for the Connection */
if (!@mysql_select_db("penpal", $link)) {
echo "<p>There has been an error. This is the error message:</p>";
echo "<p><strong>" . mysql_error() . "</strong></p>";
echo "Please Contact Your Systems Administrator with the details";
}
/* Sets the SQL Query */
if($_POST == All && $_POST == All)
{
$sql = "SELECT * FROM penpal";
}
else
if($_POST == All)
{
$sql = "SELECT * FROM penpal";
$sql .= " WHERE (penpal.province = '{$_POST}')";
}
else
if($_POST == All)
{
$sql = "SELECT * FROM penpal";
$sql .= " WHERE (penpal.type = '{$_POST}')";
}
else
if($_POST == $_POST && $_POST == $_POST)
{
$sql = "SELECT * FROM penpal";
$sql .= " WHERE (penpal.type = '{$_POST}' AND penpal.province= '{$_POST}')";
}
/* Passes a Query to the active database*/
$result = mysql_query($sql, $link);
if(!$result)
{
echo("<p>Error perfoming query: " . mysql_error() . "</p>");
exit();
}
/* Starts the table and creates headings */
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<table border=1 width=600>
<tr><td rowspan=8> ><img src="http://127.0.0.1/penpal/<;? echo {$row};?>.jpg" />
</td><td><strong><font face="verdana" size=1 color="purple"> Penpal_ID</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td></tr>"); ?>
<tr><td><strong><font face="verdana" size=1 color="purple">Type</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td></tr>"); ?>
<tr><td><strong><font face="verdana" size=1 color="purple">Details</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td></tr>"); ?>
<tr><td><strong><font face="verdana" size=1 color="purple">Country</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td></tr>"); ?>
<tr><td><strong><font face="verdana" size=1 color="purple">Province</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td></tr>"); ?>
<tr><td><strong><font face="verdana" size=1 color="purple">District</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td></tr>"); ?>
<tr><td><strong><font face="verdana" size=1 color="purple">Other Details</strong></td><? echo("<td><b><font face=verdana size=1 color=black>" . $row . "</td>\n</tr>\n\n"); ?>
<br>
<br>
<?
/* Retrieves the rows from the query result set
and puts them into a HTML table row
*/
}
/* Closes the table */
?>
</table>
<br>
<br>
Search Again:
<?
/* Closes Connection to the MySQL server */
mysql_close ($link);
/* Displays HTML Form */
html_form();
}
?>
</body>
</html>
_______________________________