doufei4418
2016-02-03 10:11
浏览 57
已采纳

使用jQuery从下拉框中定义未定义的索引

I cannot seem to get the value from my dropdown box which is using JQuery linked up to my database, into an SQL statement? Where is the error?

Thanks

Here is my PHP:

<form action="" method="post">
      <p class="timetable-p">Room code:
            <select id="combobox" name="combobox">
                <form action="" method="post"><?php
                    echo '<option class="option">Type/Select a room</option>';
                    while ($row = $res->fetchRow()) {
                        $code = $row['roomcode'];
                        $titles[] = $row['park'];
                        echo '<option class="option" name="codedrop">'.$code.'</option>';
                    }
                        ?>
                        <input type="submit" value="subm" name="subm">
                        </form>
                        <?php
                        if( isset( $_POST['subm'] ) )
                        {

                    $codedropOption= $_POST['codedrop'];

                        $resql = "SELECT * FROM 'ROOMS' WHERE 'roomCode' LIKE '$codedrop%'";
                        $res1 = mysql_query($resql);

            echo "<table>";             
            while($row = mysql_fetch_array($res1)){                         
            echo "<tr><td>" . $row['roomCode'] . "</td>";
            echo "<td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td>";
            echo "<td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td>";
            echo "<td>" . $row['wheelchairAccess'] . "</td>";
            echo "<td>" . $row['lectureCapture'] . "</td>";
            echo "<td><input type='radio' name='radioSelect' value= '". $row['roomCode']."'></td>";
            }
            echo "</table>"; 
                    }


                ?>
</form>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doupo5861 2016-02-03 10:21
    已采纳

    1) Remove name="codedrop" from <option> Like

    echo '<option class="option">'.$code.'</option>';
    

    N.B.: Only <select> bears the name attribute, not <option>.

    2) Remove first <form>, it's of no use. And even, nested <form> are not allowed.

    3) Change

    $codedropOption= $_POST['codedrop']; 
    

    To

    $codedropOption= $_POST['combobox'];
    

    to not get

    Undefined index: codedrop

    4) Change

    $resql = "SELECT * FROM 'ROOMS' WHERE 'roomCode' LIKE '$codedrop%'";
    

    To

    $resql = "SELECT * FROM ROOMS WHERE roomCode LIKE '$codedrop%'";
    

    Use backtick in place of single quotes '.

    5) Change

    $resql = "SELECT * FROM 'ROOMS' WHERE 'roomCode' LIKE '$codedrop%'";
    

    To

    $resql = "SELECT * FROM ROOMS WHERE roomCode LIKE '$codedropOption%'";
    

    Updated Code

    <form action="" method="post">
        <p class="timetable-p">Room code:
        <select id="combobox" name="combobox">
            <?php
          echo '<option class="option">Type/Select a room</option>';
          while ($row = $res->fetchRow()) {
              $code = $row['roomcode'];
              $titles[] = $row['park'];
              echo '<option class="option">'.$code.'</option>';
          }?>
        </select>
      <input type="submit" value="subm" name="subm">
    </form>
    
    <?php
    if( isset( $_POST['subm'] ) )
    {
        $codedropOption= $_POST['combobox'];
    
        $resql = "SELECT * FROM ROOMS WHERE roomCode LIKE '$codedropOption%'";
        $res1 = mysql_query($resql);
    
        echo "<table>";             
        while($row = mysql_fetch_array($res1)){                         
            echo "<tr><td>" . $row['roomCode'] . "</td>";
            echo "<td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td>";
            echo "<td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td>";
            echo "<td>" . $row['wheelchairAccess'] . "</td>";
            echo "<td>" . $row['lectureCapture'] . "</td>";
            echo "<td><input type='radio' name='radioSelect' value= '". $row['roomCode']."'></td>";
        }
        echo "</table>"; 
    }
    ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题