使用 $_POST 数据创建新的 html 表单值
我正在使用 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不应该为此使用 POST。这是 GET 的工作
shouldn't use POST for that. It's GET's job
我不清楚你的帖子做错了什么,但以下是如何正确执行此操作的基础知识:
page1.php
page2.php
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
page2.php
所以,这就是最终起作用的。我刚刚重建了第二种形式...:
它是相同的。我不知道是什么让它起作用......
无论如何,感谢大家的努力!非常感谢。
So, here's what FINALLY worked. I just rebuilt the second form...:
It's identical. I have no idea what made it work....
Anyways thanks for everyone's efforts! Its much appreciated.