As @tim already pointed out, I don't think there is a way of combining these two SQL queries together since they aren't relevant to each other. Also, your variable, table and table column naming is a bit odd.
What I've done to your code:
- Renamed the variables.
- Added the HTML5 doctype.
- Omitted the form's
action
attribute. - Disabled the first select options.
- Created a short alias function to handle html output to prevent XSS attacks.
- Used alternative
while()
syntax more suited for going in and out of PHP to output HTML. - Used
<?= $x
(shorthand for<?php echo $x;
).
Ended up with the following code:
<?php
require_once 'includes/connection.php';
$carMakeSql = 'SELECT * FROM tblmake';
$carMakeResult = $conn->query($carMakeSql);
$carClassSql = 'SELECT * FROM tblclass';
$carClassResult = $conn->query($carClassSql);
function html($string) {
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Car Makes</title>
</head>
<body>
<h3>Car Makes</h3>
<form method="GET">
<select name="makeID">
<option selected disabled>Choose Make</option>
<?php while ($result = $carMakeResult->fetch_assoc()): ?>
<option value="<?= html($result['makeID']); ?>"><?= html($result['carmake']); ?></option>
<?php endwhile; ?>
</select>
<select name="classID">
<option selected disabled>Choose Class</option>
<?php while ($result = $carMakeResult$carClassResult->fetch_assoc()): ?>
<option value="<?= html($result['classID']); ?>"><?= html($result['carclass']); ?></option>
<?php endwhile; ?>
</select>
<input type="submit" value="Insert">
</form>
</body>
</html>
(not tested)