I've installed the MySQL database using the script as in http://www.databasejournal.com/scripts/practice-sql.html :
Then I have my PHP code learnt from Youtube video about how to populate dropdown with data from SQL, but It still can't work that nothing turns out when clicking the "Show details" submit button. I am still new to PHP and can't sort it out myself. Thank you !!
// PHP Code
<?php
require'require.php';
$usersQuery="
SELECT DISTINCT
c.cno,
c.cname,
o.eno,
o.shipped
FROM customers c
RIGHT JOIN orders o
ON c.cno=o.cno
group by (c.cname)
";
$users=$db->query($usersQuery);
if(isset($_GET['user'])){
$userQuery="
{$usersQuery}
WHERE c.cno=:cno";
$user= $db->prepare($userQuery);
$user->execute(['cno'=>$_GET['user']]);
$selectedUser=$user->fetch(PDO::FETCH_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dropbox</title>
<script language=JavaScript>
</script>
</head>
<body>
<h3>My Dropdown</h3>
<form action="dropbox.php" method="get">
<select name="user">
<option value="">Choose one</option>
<?php foreach($users->fetchAll() as $user):?>
<option value="<?php echo $user['cno'];?>" <?php echo isset($selectedUser)&& $selectedUser['cno']==$user['cno']? "selected":""?> > <?php echo $user['cname'];?> </option>
<?php endforeach ?>
</select>
<input type="submit" value="Show details" >
</form>
<?php if(isset($selectedUser)):?>
<pre><?php echo($selectedUser['cno']);?></pre>
<?php endif; ?>
</body>
</html>