Incorrect integer value in INSERT INTO

Viewed 24

I am newer to PHP and I cannot get my code to work. When I submit the form I keep getting an Incorrect integer value: '' start_id at row 1 error:

I understand that the way I am writing my SQL statements can lead to SQL injections but this is how I want to have it done. I don't want prepared statements.

Here is the form code where someone can select from options and add a class to the schedule database:

  Class Date: <input type="date" name="date">

<br>

Class Start Time:
<select type="time" name="start">
    <?php
    $sql = "SELECT * from starts";

    $results = $mysql -> query($sql);
    if(!$results){
        echo "SQL ERROR! " . $mysql -> error;
        echo "<br>" . $sql . "<br>";
    }

    while($currentrow = $results -> fetch_assoc()) {
        echo "<option value=''" . $currentrow["start_id"] .'>' . $currentrow["start"] . "</option>";
    }
    ?>

</select>
<br>

Class End Time:
<select type="time" name="end">
    <?php
    $sql = "SELECT * from ends";

    $results = $mysql -> query($sql);
    if(!$results){
        echo "SQL ERROR! " . $mysql -> error;
        echo "<br>" . $sql . "<br>";
    }

    while($currentrow = $results -> fetch_assoc()) {
        echo "<option value=''" . $currentrow["end_id"] .'>' . $currentrow["end"] . "</option>";
    }
    ?>

</select>
<br> Room Number: <select  name="room">
    <?php
    $sql = "SELECT * from classrooms";

    $results = $mysql -> query($sql);
    if(!$results){
        echo "SQL ERROR! " . $mysql -> error;
        echo "<br>" . $sql . "<br>";
    }

    while($currentrow = $results -> fetch_assoc()) {
        echo "<option value=''" . $currentrow["classroom_id"] .'>' . $currentrow["classroom"] . "</option>";
    }
    ?>

</select>
<br>Class Type:
<select  name="type">
    <?php
    $sql = "SELECT * from types";

    $results = $mysql -> query($sql);
    if(!$results){
        echo "SQL ERROR! " . $mysql -> error;
        echo "<br>" . $sql . "<br>";
    }

    while($currentrow = $results -> fetch_assoc()) {
        echo "<option value=''" . $currentrow["type_id"] .'>' . $currentrow["type"] . "</option>";
    }
    ?>

</select>
<br>


Class Name:
<select name="name">
    <?php
    $sql = "SELECT * from names";

    $results = $mysql -> query($sql);
    if(!$results){
        echo "SQL ERROR! " . $mysql -> error;
        echo "<br>" . $sql . "<br>";
    }

    while($currentrow = $results -> fetch_assoc()) {
        echo "<option value=''" . $currentrow["name_id"] .'>' . $currentrow["name"] . "</option>";
    }
    ?>

</select>
<br>

<input type="submit">

And here is the INSERT INTO code:

    $date = $_REQUEST['date'];
$start = $_REQUEST['start'];
$end = $_REQUEST['end'];
$room = $_REQUEST['room'];
$type = $_REQUEST['type'];
$name = $_REQUEST['name'];


$sql = "INSERT INTO class_schedule
       (date, start_id, end_id, classroom_id, type_id, name_id)
        VALUES ('$date', '$start', '$end', '$room', '$type', '$name')";


$date = strtotime($_REQUEST["date"]);
$start = strtotime($_REQUEST["start"]);
$end = strtotime($_REQUEST["end"]);

echo "<br>" . $sql;

$results = $mysql ->query($sql);

if(!$results){
    echo "SQL ERROR! " . $mysql -> error;
    echo "<br>" . $sql . "<br>";
} else {
    echo "SUCCESS! Record Added!";
}

?>

I set each of the columns as variables but for some reason, I keep getting the integer error. When a user selects a start time from the form it should add it to the database but there seems to be something wrong with my code.

0 Answers
Related