简体   繁体   中英

HY093 Error PDO dropdown list of available rooms

Please help, trying to create a booking form where the user will get a dropdown list of available rooms with the capacity stated in the field above.

I'm new to PDO and trying to learn but can't seem to find the answer on my own.

ATM, the dropdown list says "NOTICE: Undefined index: ... on line 29 ... SQLSTATE(HY093)"

line 29 is: $group = $_GET['groupsize']; Tried a lot of different values and keep getting errors with the list.

<input type="text" name="groupsize"><br>



<select id="roomID" name="roomID">                      
<option value="">
<?php 
    $DBH = new PDO("mysql:host=localhost;dbname=reserve", 'root', '');

    $group = $_GET['groupsize'];

    $ROOMS = $DBH->prepare("SELECT ROOM_NAME FROM room WHERE capacity = :group");
    $ROOMS->execute();

    $ROOMS->bindParam(':group', $group);

    while($result = fetchAll($ROOMS)){
        echo '<OPTION VALUE="$result[0]">"$result[]"</OPTION>';
    }
?>
</select>

Change

$ROOMS = $DBH->prepare("SELECT ROOM_NAME FROM room WHERE capacity = :group");
$ROOMS->execute();

$ROOMS->bindParam(':group', $group);

To

$ROOMS = $DBH->prepare("SELECT ROOM_NAME FROM room WHERE capacity = :group");
$ROOMS->bindValue(':group', $group);
$ROOMS->execute();

This is my whole booking.php files body content. Tried a few things and got the error away but then the dropdown list did not show anything.

As i said, im new to this so might be simple but i can't see it :/

<form action="reservation.php" method="_POST">
Dato:<br>
<input type="date" name="date"><br>
Fra:<br>
<input type="time" name="start"><br>
Til:<br>
<input type="time" name="endT"><br>
Tittel for booking:<br>
<input type="text" name="title"><br>
Ditt brukernavn (8 tegn):<br>
<input type="text" name="userID"><br>
Gruppestørrelse:<br>
<input type="text" name="groupsize"><br>
Velg tilgjengelig rom:<br>

<select id="roomID" name="roomID">                      
<option value="">
<?php 
    $DBH = new PDO("mysql:host=localhost;dbname=reserve", 'root', '');

    $group = $_GET['groupsize'];

    $ROOMS = $DBH->prepare("SELECT ROOM_NAME FROM room WHERE capacity = :group");
    $ROOMS->bindValue(':group', $group);
    $ROOMS->execute();

    if($ROOMS->rowCount() > 0){
        echo '<OPTION VALUE="$result[0]">"$result[]"</OPTION>';
    }
    else{
        echo 'Ingen rom tilgjengelig.';
    }
?>
</select><br><br><br>


<!--<select name="roomID"></select><br> -->

<input type="reset" value="tilbakestill"><input type="submit" value="Send booking">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM