dongpo8702 2015-05-04 21:49
浏览 26

html表里面的表单,并用PHP获取值

<!DOCTYPE html>
<html lang="ro">
<head>
        <title>MODIFICA</title>
</head>
<body>
        <?php
        $select1 = isset($_POST['select1']) ? $_POST['select1'] : '';
        if($select1 == 'da'){echo 'ok';}
        else { echo '!ok'; }
        ?>
        <form method="POST">
        <table border="1">
                <thead>
                        <tr>
                                <th>Nume</th>
                                <th>Prenume</th>
                                <th>Adresa</th>
                                <th>Partid</th>
                                <th>Consiliul Local</th>
                                <th>Primar</th>
                                <th>Consiliul Judetean</th>
                                <th>Presedinte Consiliul Judetean</th>
                                <th>Senat</th>
                                <th>Deputat</th>
                                <th>Comisia Europarlamentara</th>
                                <th>Presedinte</th>
                                <th>Submit</th>
                        </tr>
                </thead>
                <tbody>
                        <?php
                        $stmt = $db->prepare('SELECT nume,prenume,adresa,partid,consiliul_local FROM candidati');
                        $stmt->execute();
                        while($row = $stmt->fetch(PDO::FETCH_OBJ)):?>
                        <tr>
                                <td><?php echo $row->nume;?></td>
                                <td><?php echo $row->prenume;?></td>
                                <td><?php echo $row->adresa;?></td>
                                <td><?php echo $row->partid;?></td>
                                <td>
                                        <select name="select1">
                                                 <option value=""></option>
                                                 <option value="<?php echo $row->consiliul_local;?>">
                                                                <?php echo $row->consiliul_local;?>
                                                 </option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select2">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select3">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select4">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select5">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select6">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select7">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <select name="select8">
                                                <option value=""></option>
                                                <option value="da">DA</option>
                                        </select>
                                </td>
                                <td>
                                        <button type="submit" name="btn">SUBMIT</button>
                                </td>
                        </tr>
                        <?php endwhile;?>
                </tbody>
        </table>
        </form>
</body>
</html

I just verify if the $select1 variable is set, and if it's the case, then if the value from "option" (line 44), is 'da', then display it.

The problem that I have is that value is not displayed accordingly. Anyone knows why, and what should I change in order to work? Or, in simple words, for starting coding the page I need, firstly I just filled-in that "option" tag with the value from db (and yes, the value 'da' is presented in 'consiliul_local' field from db), and then I made a simple echo, above the "form", and if the value of the "select" is 'da', then it should display the message 'ok'. But it always displays the message placed on the else branch. I must specify that I must do the whole logic only with php, and not js or anything else.

Here is how my page looks like, and notice that selected 'da' in the dropdown, which is there because of the MySQL fetch (line 35 in pastebin). http://www.2shared.com/photo/eXzJ7Glo/1_online.html

This is the page source, which says the value stored in db, is correctly inserted into that value attribute of the tag. http://www.2shared.com/uploadComplete.jsp?sId=CACRC8H4n6GrF0jJ

So I select 'da' from that dropdown, then I press the button, and I expect the 'ok' message to be displayed. Any fix? Thanks so much!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c