gpt4 book ai didi

php - 使用 $_POST 数据创建新的 html 表单值

转载 作者:行者123 更新时间:2023-11-29 02:36:01 24 4
gpt4 key购买 nike

我正在使用 post将信息发送到我的页面。我用它来创建一个变量并将该变量传递给一个新的 <input> .但是,当我提交新表单时,变量为空。

变量是从发布数据创建的:

$timenotstarted = $_POST["placeholder"]; 

然后在 html 中内联:

<form name="newform" method="post" action="insert.php">
<input type="text" name="timerset" value="<?php echo $timenotstarted; ?>">
<input type="submit" value="Submit"><
</form>

提交新表单时,name="timerset" 的变量, 为空白。

当我回应 $timenotstarted在此表单所在的同一页面上,

它会显示它的值(value)。当我尝试以新形式使用它时,它就“消失了”。

编辑:这是正在发生的事情: enter image description here

不确定这是否有帮助:http://forexguruguide.com/timer/insert.php

这是整个 shabang:

<?php include 'connect.php';
$timenotstarted = $_GET["placeholder"];
$start = $_POST["start"];
$timerset = $_post["timerset"];
echo $timenotstarted . '<br />';
echo $start . '<br />';
echo $timerset . '<br />';
?>

<form name="timeform" method="get" action="insert.php">
<select name="placeholder">
<option value="1">1 min</option>
<option value="3">3 min</option>
<option value="5">5 min</option>
<option value="10">10 min</option>
</select>
<input type="submit" value="Set timer">
</form>

<form name="startform" method="post" action="insert.php">
<input type="hidden" value="1" name="start">
Timer set to: <input type="text" name="timerset" value="<?php print $timenotstarted?>">
<input type="Submit" value="Start Timer">
</form>

<?php

if ($start==1) {
$target = time() + ($timerset * 60);
mysql_query("UPDATE countdowntimer SET target='$target' WHERE id='0'");
mysql_query("UPDATE countdowntimer SET timenotstarted='null' WHERE id='0'");
echo 'Timer started' . '<br />';
echo $target . '<br />';
echo time(); }
else if (!empty($timenotstarted)) {
$timenotstarted .= ":00";
mysql_query("UPDATE countdowntimer SET timenotstarted='$timenotstarted'");
echo 'Timer set to: ' . $timenotstarted; }
else {
echo 'Set the timer then start the timer'; }
?>

最佳答案

不应该为此使用 POST。这是 GET 的工作

<? if (!isset($_GET['placeholder'])): ?>
<form>
Enter placeholder:
<input type="text" name="placeholder" value="">
<input type="submit" value="Submit">
</form>
<? else: ?>
<form name="newform" method="post" action="insert.php">
<input type="text" name="timerset" value="<?=htmlspecialchers($_GET["placeholder"])?>">
<input type="submit" value="Submit">
</form>
<? endif ?>

关于php - 使用 $_POST 数据创建新的 html 表单值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5055587/

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