Skip to main content
added 1 character in body
Source Link
Kid Diamond
  • 2.6k
  • 16
  • 35

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)

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->fetch_assoc()): ?>
                <option value="<?= html($result['classID']); ?>"><?= html($result['carclass']); ?></option>
            <?php endwhile; ?>
            </select>

            <input type="submit" value="Insert">
        </form>
    </body>
</html>

(not tested)

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 = $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)

added 2 characters in body
Source Link
Kid Diamond
  • 2.6k
  • 16
  • 35

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($sql1$carMakeSql);

$carClassSql    = 'SELECT * FROM tblclass';
$carClassResult = $conn->query($sql2$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->fetch_assoc()): ?>
                <option value="<?= html($result['classID']); ?>"><?= html($result['carclass']); ?></option>
            <?php endwhile; ?>
            </select>

            <input type="submit" value="Insert">
        </form>
    </body>
</html>

(not tested)

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.


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($sql1);

$carClassSql    = 'SELECT * FROM tblclass';
$carClassResult = $conn->query($sql2);

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->fetch_assoc()): ?>
                <option value="<?= html($result['classID']); ?>"><?= html($result['carclass']); ?></option>
            <?php endwhile; ?>
            </select>

            <input type="submit" value="Insert">
        </form>
    </body>
</html>

(not tested)

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->fetch_assoc()): ?>
                <option value="<?= html($result['classID']); ?>"><?= html($result['carclass']); ?></option>
            <?php endwhile; ?>
            </select>

            <input type="submit" value="Insert">
        </form>
    </body>
</html>

(not tested)

Source Link
Kid Diamond
  • 2.6k
  • 16
  • 35

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.


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($sql1);

$carClassSql    = 'SELECT * FROM tblclass';
$carClassResult = $conn->query($sql2);

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->fetch_assoc()): ?>
                <option value="<?= html($result['classID']); ?>"><?= html($result['carclass']); ?></option>
            <?php endwhile; ?>
            </select>

            <input type="submit" value="Insert">
        </form>
    </body>
</html>

(not tested)