Im using a dropdown box on page one that should pass the vairable to the linked page and on the second use that variable"$id" on the second in mysql query.
first page code to select who to look up
Customer Lookup
require ('dbconnect.php');
$result = $con->query("select id, lastname, firstname from customer");
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['lastname'];
$firstname = $row['firstname'];
echo '<option value="/customerpage.php?='.$id.'">'.$name.','.$firstname.'</option>';
}
echo "</select>";
mysqli_close($con);
?>
Second page which is the receiving page
$id = $_GET['id'];
echo $id;
require ('dbconnect.php');
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM customer WHERE id='$id'");
while($row = mysqli_fetch_array($result)) {
echo $row['firstname'];
echo "<br>";
}
?>
the second page url comes up great with /customerpage.php?=1
try this:
$result = mysqli_query($con,"SELECT * FROM customer WHERE id=' . $id . '");
I think you are passing id from select box to another php page. You should use id
as key in query string.
echo '<option value="/customerpage.php?id='.$id.'">'.$name.','.$firstname.'</option>';
Now, in your second file you are getting it from $_GET
Your query will be -
$result = mysqli_query($con,"SELECT * FROM customer WHERE id=$id");
On the first page in the option your omitted the key 'id'
echo '<option value="/customerpage.php?id='.$id.'">'.$name.','.$firstname.'</option>';