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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?