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

发布于 2024-10-18 03:49:51 字数 2306 浏览 2 评论 0原文

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

该变量是根据发布数据创建的:

$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 时,

它将显示其值。当我尝试以新形式使用它时,它就“消失了”。

编辑:这是发生的事情: 在此处输入图像描述

不确定这是否有帮助: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'; }
?>

I'm using post to send info to my page. I'm using that to create a variable and pass that variable to a new <input>. However, when I submit the new form, the variable is blank.

The variable is created from post data:

$timenotstarted = $_POST["placeholder"]; 

Then inline in the html:

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

When the new form is submitted, the variable whose name="timerset", is blank.

When I echo $timenotstarted on the same page that this form is,

it will show its value. It just "goes away" when I try to use it in the new form.

Edit: Here's what's happeneing:
enter image description here

Not sure if this helps: http://forexguruguide.com/timer/insert.php

And here's the whole 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'; }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日久见人心 2024-10-25 03:49:51

不应该为此使用 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 ?>

shouldn't use POST for that. It's GET's job

<? 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 ?>
旧竹 2024-10-25 03:49:51

我不清楚你的帖子做错了什么,但以下是如何正确执行此操作的基础知识:

page1.php

<form action="page2.php" method="post">
<input type="hidden" name="foo" value="bar"/>
<input type="submit"/>
</form>

page2.php

<form>
<input name="foo2" value="<?php echo htmlspecialchars($_POST['foo']); ?>"/>
</form>

It's not clear to me what you're doing wrong from your post, but here's the basics on how to do it right:

page1.php

<form action="page2.php" method="post">
<input type="hidden" name="foo" value="bar"/>
<input type="submit"/>
</form>

page2.php

<form>
<input name="foo2" value="<?php echo htmlspecialchars($_POST['foo']); ?>"/>
</form>
烦人精 2024-10-25 03:49:51

所以,这就是最终起作用的。我刚刚重建了第二种形式...:

<form name="testyboy" method="post" action="insert.php">
<input type="hidden" value="1" name="start">
<input type="hidden" value="<?php print $timenotstarted?>" name="testyboy">
<input type="submit" value="Start Timer">
</form>

它是相同的。我不知道是什么让它起作用......

无论如何,感谢大家的努力!非常感谢。

So, here's what FINALLY worked. I just rebuilt the second form...:

<form name="testyboy" method="post" action="insert.php">
<input type="hidden" value="1" name="start">
<input type="hidden" value="<?php print $timenotstarted?>" name="testyboy">
<input type="submit" value="Start Timer">
</form>

It's identical. I have no idea what made it work....

Anyways thanks for everyone's efforts! Its much appreciated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文