dpjpo746884 2011-06-14 20:46
浏览 42
已采纳

HTML / PHP调查没有正确地从表中传递ID

I'll try to keep it simple... this is the code I am using to populate a dropdown menu from a database. This populates the dropdown menu correctly.

<form action="formsubmit.php?team_id=6" method="post">
    <label> <br />What did they say?: <br />
        <textarea name="quotetext" rows="10" cols="26"></textarea></label>
    <select name='name'>
        <?php
            while ($temp = mysql_fetch_assoc($query)) {
                echo "<option value=" . $temp['id'] . ">".htmlspecialchars($temp['lastname']) . ", " . htmlspecialchars($temp['firstname']) . "</option>";
            }
        ?>
    </select>
    <input type="submit" value="Submit!" />
</form>

What I'm attempting to do is pass the person's ID into along to the file formsubmit.php which is called on the submission of the form. When I use $die($sql) on my database query in formsubmit.php, the ID of the person is blank.... everything else gets passed through just fine. Here is the relevant code in formsubmit.php:

$quotetext = $_POST['quotetext'];
    $id = $_POST['id'];
    $team_id = $_GET['team_id'];
    $sql = "INSERT INTO quotes SET 
            speaker_id='$id',
            quotetext='$quotetext',
            game_id=2";
    die($sql);

EDIT: Fixed, credit to Michael.

<select name='name'>

Should be:

<select name='id'>
  • 写回答

5条回答 默认 最新

  • douyo770657 2011-06-14 20:49
    关注

    In your form, you are using <select name='name'>, but in your PHP script you're calling for $_POST['id']. Change it to:

    <select name='id'>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

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