doyrte8419 2014-08-11 02:19
浏览 39
已采纳

PHP MYSQL:无法从下拉框和文本框中插入数据

I am trying to insert data that the user submits from a drop down box and a text box, however this data is not being inserted into my Database Table.

The Drop Down and text box code:

echo    'Tasks: <select name="selected_task">
                  <option value=""> ---Select ---- </option><br><br><br><br>';

   /*
   Query code to retrieve options goes here and assign it to a variable named '$tasks'
   */


        while ($row_list = mysql_fetch_assoc($tasks))
          { 

        echo  '<option>' . $row_list['taskname'];
                    if ($row_list['taskname']==$select) { echo $row_list['taskname']; }
        echo '</option>';
                  }
        echo '</select>';  

        echo '<div id="task_hours"> 

  <form name="hours" method="post" action="login.php?action=hours"> 
    Hours: <input type="text" name="hours" value="" /><br />  
    <input type="submit" name="submit" value="Submit" /> 
  </form> 
</div>';

Database insertion code :

$posted_client = $_POST['selected_client'];
    $posted_task = $_POST['selected_task'];
    $conn_task = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
    $inserted_time = "INSERT INTO tasks (taskhours) VALUES :posted_hours WHERE taskname = :posted_task ";
    $sp = $conn_task ->prepare ( $inserted_time);
    $sp->bindValue(":posted_hours", $posted_hours, PDO::PARAM_STR); // Make sure you use PDO::PARAM_STR for decimals
    $sp->bindValue(":posted_task", $posted_task, PDO::PARAM_STR); 
    $sp->execute();
    $conn_task = null;
    echo "Your total time has been entered!<br>";
    echo "Your Total Hours: " . $posted_hours;

When the form appears and I click on the 'submit' button after entering data, no error message appears but the number of hours for the table field 'taskhours' is not being updated.

  • 写回答

2条回答 默认 最新

  • dqch34769 2014-08-11 03:39
    关注

    <Select>tag is a Element Of Form So when you use outside form then it doesn't work. so you have put the <Select> ('dropdown') is inside the <form> then your action page put below code and check you got the data or not in your post method.

    <?php echo "<pre>"; print_r($_POST); ?>

    here you got the all the form data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能