Hi All,
I am a newcomer to PHP and still learning. Any help with this problem would be appreciated.
Please see the code below. Whenever I run this I get an error message:
"Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in
C:\wamp\www\selected.php on line 25"
Can someone tell me what Iam doing wrong?
<html>
<Head>
<Title>Drop Down Choice Example</title>
<?php
//connect to database, checking, etc
include_once "connect.php";
// process form when posted
if(isset($_POST['value'])) {
if($_POST['value'] == 'Kulp') {
// query to get all Kulp records
$query = "SELECT * FROM names WHERE LastName='Kulp'";
}
elseif($_POST['value'] == 'Smith') {
// query to get all Smith records
$query = "SELECT * FROM names WHERE LastName='Smith'";
} else {
// query to get all records
$query = "SELECT * FROM names";
}
$sql = mysql_query($query);
while ($row = mysql_fetch_array($query)){
$Id = $row["Id"];
$FirstName = $row["FirstName"];
$LastName = $row["LastName"];
// Echo your rows here...
echo 'The user ID is:' . $row['id'];
}
}
?>
</head>
<body>
<P>Please select from below<p><BR>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' >
<select name="value">
<option value="All">All</option>
<option value="Kulp">Kulp</option>
<option value="Smith">Smith</option>
</select>
<br />
<input type='submit' value = 'Filter'>
</form>