【发布时间】:2011-06-30 15:31:42
【问题描述】:
我正在使用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 时,
它将显示其价值。当我尝试以新形式使用它时,它只会“消失”。
编辑:这是发生的事情:
不确定这是否有帮助:http://forexguruguide.com/timer/insert.php
这是整个沙班:
<?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'; }
?>
【问题讨论】:
-
所以你的第一行代码在
insert.php? -
关键的 'placeholder' 不应该是 'timerset' 吗?
-
@jondavidjohn,是的,第一行也在 insert.php 中。为了澄清,我将发布到同一页面。
-
应该使用
$_POST['timerset']而不是$_POST['placeholder'],正如@GWW 所说。另外,请使用<?php echo htmlspecialchars($timenotstarted); ?>来避免XSS攻击。 -
@Mark 这不是为了避免任何事情。它是 HTML 标准所要求的。即使没有什么可以保护的。
标签: php mysql forms input echo