biscuitboy
Technical User
Hi all,
Im trying to create a simple script to search a mysql database and search by the surname of the entries. Ufortunatly I have tried this script in the browser and doesnt seem to work.
I have created a connect.php script which I know works and so I know that isnt the problem.
Could someone have a quick look at it as im sure its a simple thing that I have missed but its driving me mad.
Best regards
<?php # Scrtipt 6.6 - Searchbysurname.php
$page_title = 'Search By Surname';
if (isset($_POST['submit'])) { // Handle the form.
$message = NULL;
if (empty($_POST['surname'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter a surname!</p>';
} else {
$ln = $_POST['surname'];
}
if ($ln) { //if everthings is ok.
require_once ('connect.php'); // Connect to the db.
//Make the Query
$query = "SELECT first_name, surname FROM Residents WHERE surname= '$ln'";
$result = mysql_query ($query); // run the query
if ($result) {
echo '<table align="centre"
cellspacing="2" cellpadding="2">
<tr><td align="left"><b>Name</b>
</td></tr>
';
//fetch and print all the records.
while ($row = mysql_fetch_array($result)) {
echo "<tr><td align=\"left\">" .
stripslashes($row[0]) . "</td>
<td align=\"left\">$row[1]</td>
</tr>\n";
}
echo '</table>';
mysql_free_result ($result); //Free up the resources.
} else { // if it did not run ok
echo '<p>There are currently no registered residents.</p>';
}
mysql_close(); // close the database connection
} else {
$message .= '<p>Please try again.</p>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<fieldset><legend>Enter a Surname below:</legend>
<p><b>Last Name:</b> <input type="text" name="surname" size="30" maxlength="30" value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<div align="centre"><input type="submit" name"submit" value="Search" /></div>
</form><!-- end of form -->
Im trying to create a simple script to search a mysql database and search by the surname of the entries. Ufortunatly I have tried this script in the browser and doesnt seem to work.
I have created a connect.php script which I know works and so I know that isnt the problem.
Could someone have a quick look at it as im sure its a simple thing that I have missed but its driving me mad.
Best regards
<?php # Scrtipt 6.6 - Searchbysurname.php
$page_title = 'Search By Surname';
if (isset($_POST['submit'])) { // Handle the form.
$message = NULL;
if (empty($_POST['surname'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter a surname!</p>';
} else {
$ln = $_POST['surname'];
}
if ($ln) { //if everthings is ok.
require_once ('connect.php'); // Connect to the db.
//Make the Query
$query = "SELECT first_name, surname FROM Residents WHERE surname= '$ln'";
$result = mysql_query ($query); // run the query
if ($result) {
echo '<table align="centre"
cellspacing="2" cellpadding="2">
<tr><td align="left"><b>Name</b>
</td></tr>
';
//fetch and print all the records.
while ($row = mysql_fetch_array($result)) {
echo "<tr><td align=\"left\">" .
stripslashes($row[0]) . "</td>
<td align=\"left\">$row[1]</td>
</tr>\n";
}
echo '</table>';
mysql_free_result ($result); //Free up the resources.
} else { // if it did not run ok
echo '<p>There are currently no registered residents.</p>';
}
mysql_close(); // close the database connection
} else {
$message .= '<p>Please try again.</p>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<fieldset><legend>Enter a Surname below:</legend>
<p><b>Last Name:</b> <input type="text" name="surname" size="30" maxlength="30" value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<div align="centre"><input type="submit" name"submit" value="Search" /></div>
</form><!-- end of form -->