开发者

Using $_POST data to create a new html form value

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:

Using $_POST data to create a new html form value

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

And here's the whole shabang:

<?php include 'connect.php';
$timenotstarted = $_GET["placeholder"];
$star开发者_运维知识库t = $_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'; }
?>


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 ?>


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜