Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP search database and return results. 1

Status
Not open for further replies.

VitoCorleone

Programmer
Jun 22, 2004
28
GB
i have a form where a user can search the database STAFF, here they insert a staff number and press submit.

the next page is using the $_Post to retrieve that value on the previous page and display the records. however its not working.

Can you help? Any sites?

Here is the code on my 2nd page:

<?php
// Database connection variables
$dbServer = "localhost";
$dbDatabase = "dreamhome";
$dbUser = "root";
$dbPass = "harry";

$sConn = mysql_connect($dbServer, $dbUser, $dbPass)
or die("Couldn't connect to database server");
$dConn = mysql_select_db($dbDatabase, $sConn)
or die("Couldn't connect to database $dbDatabase");

$result = mysql_query("SELECT * FROM staff WHERE staff_no = '" . $_POST['staffno'] ."'",$db);

echo "<table border=1>\n";

echo "<tr><td>staff Number</td><td>name</tr>\n";

while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td></tr>\n",
$myrow[1], $myrow[2], $myrow[3]);

}
echo "</table>\n";
?>
 
i agree with sleipnir214 - this is just a basic debugging issue.

but ... since i've spotted the error - the resource handle at the end of your mysql_query should be $dConn.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top