chornbeck
02-02-2006, 04:52 PM
OK, here's the deal. Have an HTML form that asks for a person's last name. It then must query my MySQL DB and return all 4 fields for each record that matches the last name that was entered (some last names have up to 10-11 records).
Here is my form:
<form method="POST" action="lookup.php">
Last Name:<br><br>
<input type="text" name="LstName" value=""><br><br>
<input type="submit" name="submit" value="submit"></form>
And here is the PHP process..
<?
if($_POST['submit']){
mysql_connect ("localhost","orlandoi_referra","referral2");
mysql_select_db ("orlandoi_referralowners") or die ('I cannot connect to the
database because: ' . mysql_error());;
$LstName=$_POST['LstName'];
$result = mysql_query("SELECT * FROM owner_data WHERE LastName=$LstName")
or die(mysql_error());
$row = mysql_fetch_array($result);
// Print out the contents of the entry
echo "First: ".$row['FirstName'];
echo "Last: ".$row['LastName'];
echo "ZIP: ".$row['PostalCode'];
echo "OwnerID: ".$row['OwnerID'];
}
?>
I keep getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/orlandoi/public_html/referral/lookup.php on line 15
Also, my knowledge is very limited, but I believe I need to set up some kind of loop to display all pertinent records (which I don't know how to do).
If anyone can point me in the right direction, it would be greatly appreciated!
Here is my form:
<form method="POST" action="lookup.php">
Last Name:<br><br>
<input type="text" name="LstName" value=""><br><br>
<input type="submit" name="submit" value="submit"></form>
And here is the PHP process..
<?
if($_POST['submit']){
mysql_connect ("localhost","orlandoi_referra","referral2");
mysql_select_db ("orlandoi_referralowners") or die ('I cannot connect to the
database because: ' . mysql_error());;
$LstName=$_POST['LstName'];
$result = mysql_query("SELECT * FROM owner_data WHERE LastName=$LstName")
or die(mysql_error());
$row = mysql_fetch_array($result);
// Print out the contents of the entry
echo "First: ".$row['FirstName'];
echo "Last: ".$row['LastName'];
echo "ZIP: ".$row['PostalCode'];
echo "OwnerID: ".$row['OwnerID'];
}
?>
I keep getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/orlandoi/public_html/referral/lookup.php on line 15
Also, my knowledge is very limited, but I believe I need to set up some kind of loop to display all pertinent records (which I don't know how to do).
If anyone can point me in the right direction, it would be greatly appreciated!