gpt4 book ai didi

PHP MYSQL : Cannot insert data from drop down box and a text box

转载 作者:行者123 更新时间:2023-11-29 12:47:33 25 4
gpt4 key购买 nike

我试图插入用户从下拉框和文本框中提交的数据,但是该数据没有插入到我的数据库表中。

下拉菜单和文本框代码:

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>';

数据库插入代码:

$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;

当表单出现并在输入数据后单击“提交”按钮时,不会出现错误消息,但表字段“taskhours”的小时数不会更新。

最佳答案

<Select>标签是表单元素,因此当您使用外部表单时它不起作用。所以你已经输入了 <Select> ('dropdown') 位于 <form> 内然后你的操作页面放置下面的代码并检查你是否在你的发布方法中获取了数据。

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

这里你得到了所有的表单数据。

关于PHP MYSQL : Cannot insert data from drop down box and a text box,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25235058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com