从php表单输入不在其他页面中填充值

时间:2013-05-26 00:01:59

标签: php

我已经阅读了多个问题并且无法找到一个直接回答我想要完成的问题。我在其他发布的答案中尝试了几个建议,但仍然没有我想要的结果。

我正在尝试从single_name表单获取填充到我的示例页面(single2.php)。

以下是single_name.php上的代码:

<form name="singlename" method="post" action="./single2.php" id="Form1" onsubmit="return Validatesinglename(this)">
<div id="wb_Text1" style="position:absolute;left:10px;top:15px;width:81px;height:16px;z-index:0;text-align:left;"><span style="color:#000000;font-family:Arial;font-size:13px;">Name:</span></div><input type="text" id="name" style="position:absolute;left:101px;top:15px;width:198px;height:23px;line-height:23px;z-index:1;" name="name" value="" autocomplete="off">
<div id="wb_Text2" style="position:absolute;left:10px;top:45px;width:81px;height:16px;z-index:2;text-align:left;"><span style="color:#000000;font-family:Arial;font-size:13px;">Gender:</span></div><input type="text" id="gender" style="position:absolute;left:101px;top:45px;width:198px;height:23px;line-height:23px;z-index:25;" name="Gender" value="">
<div id="wb_Text3" style="position:absolute;left:10px;top:75px;width:81px;height:16px;z-index:4;text-align:left;"><span style="color:#000000;font-family:Arial;font-size:13px;">Date of Birth:</span></div><input type="date" id="dob" style="position:absolute;left:101px;top:75px;width:198px;height:23px;line-height:23px;z-index:5;" name="dob:" value="" autocomplete="off">
<div id="wb_Text4" style="position:absolute;left:10px;top:105px;width:81px;height:16px;z-index:6;text-align:left;"><span style="color:#000000;font-family:Arial;font-size:13px;">Message:</span></div><input type="text" id="message" style="position:absolute;left:101px;top:105px;width:198px;height:23px;line-height:23px;z-index:7;" name="Message:" value="" autocomplete="off">
<input type="submit" id="Button1" name="" value="Send" style="position:absolute;left:101px;top:135px;width:96px;height:25px;z-index:8;">
<input type="reset" id="Button2" name="" value="Reset" style="position:absolute;left:207px;top:136px;width:96px;height:25px;z-index:9;">
</form>

以下是single2.php上的内容:

<div id="wb_Text1" style="position:absolute;left:428px;top:514px;width:515px;height:391px;text-align:center;z-index:29;">
   echo $_POST["name"]; 
}
?></strong></span><span style="color:#000000;font-family:Chancellor;font-size:19px;">
<br>
<br>
Local Origin of Name:&nbsp; Unique and Original<br>From the name
<?php
{
   echo $_POST["name"]; 
}    <br>
<br>
Evaluation Meaning:&nbsp; Festive, Joyous
<br>
<br>
<strong>&#0042;</strong> Emotional Spectrum <strong>&#0042;</strong>
<br>
Up front and honest
<br>
<strong>&#0042;</strong> Personal Integrity <strong>&#0042;</strong>
<br>
Friends know that
<?php
{
   echo $_POST["name"]; 
?>
can be called on in a crisis.
<br>
<strong>&#0042;</strong> Personality <strong>&#0042;</strong>
<br>
Life in the fast lane, tempered by common sense.
<br>
<strong>&#0042;</strong>&nbsp; Relationships <strong>&#0042;</strong>
<br>
Stays true and loyal
<br>
<br>

<?php
{
   echo $_POST["name"]; 
}
?>    is a 
<?php
{
   echo $_POST["gender"]; 
}
?>
<br>
<br>
{
   echo $_POST["name"]; 
}
?>
was born 
<?php
{
   echo $_POST["dob"]; 
}
?>
<br>
<br>
</span>
<span style="color:#000000;font-family:Georgia;font-size:27px;"><strong><em>
<?php
{
   echo $_POST["message"]; 
}
?></em></strong>
</span>

我可以在每个地方发布“名称”,但“性别”,“dob”和“消息”不会发布。

非常感谢任何帮助。

6 个答案:

答案 0 :(得分:2)

 name="name"
 name="Gender" 
 name="dob:"
 name="Message:" 

所以,post应该是相同的情况

$_POST['name']
$_POST['Gender']
$_POST['dob:']
$_POST['Message:']

答案 1 :(得分:1)

你在single_name.php

上拼错了你的名字
name="Gender"
name="dob:"
name="Message:"

必须使用相同的名称(不带冒号的小写)

答案 2 :(得分:0)

<input name="Gender" >#name should be 'gender' not 'Gender'
<input name="dob:" >#name should be 'dob' not 'dob:'
<input name="Message:" >#name should be 'message' not be 'Message:'

以后,您的输入name的名称应与您的帖子值匹配,并且区分大小写,以便“性别”!==“性别”等等

答案 3 :(得分:0)

您的姓名与所述内容不符。查看所遇到的内容的简便方法是在Single_2.php页面中添加调试标记: 的print_r($ _ POST); 这会在使用时“弄乱你的页面”,但会允许你看到整个$ _POST数组,其中包含正在发生的键和数据。然后你可以检查姓名等。

要以更易读的格式查看数组,请单击鼠标右键并单击“检查元素”

答案 4 :(得分:0)

尝试插入此类调试代码,并查看POST数组中存储的密钥:

echo '<pre>'
var_dump($_POST);

并且尽量不要在输入名称中使用特殊符号,因为这个例子不会真正起作用:

$_POST['dob:'] = 'somevalue';

foreach($_POST as $key=>$value){
    $$key = $value;
}

答案 5 :(得分:0)

将以下更正的代码剪切并粘贴到您的应用程序中。它已经过测试并且工作正常。

“single_name.php”如下:


<form id="Form1" action="./single2.php" method="post" name="singlename" onsubmit="return Validatesinglename(this)">

<div id="wb_Text1" style="position: absolute; left: 10px; top: 15px; width: 81px; height: 16px; z-index: 0; text-align: left;">
    <span style="color: #000000; font-family: Arial; font-size: 13px;">Name:</span></div>
<input id="name" autocomplete="off" name="name" style="position: absolute; left: 101px; top: 15px; width: 198px; height: 23px; line-height: 23px; z-index: 1;" type="text" value="">

<div id="wb_Text2" style="position: absolute; left: 10px; top: 45px; width: 81px; height: 16px; z-index: 2; text-align: left;">
    <span style="color: #000000; font-family: Arial; font-size: 13px;">Gender:</span></div>
<input id="gender" name="gender" style="position: absolute; left: 101px; top: 45px; width: 198px; height: 23px; line-height: 23px; z-index: 25;" type="text" value="">

<div id="wb_Text3" style="position: absolute; left: 10px; top: 75px; width: 81px; height: 16px; z-index: 4; text-align: left;">
    <span style="color: #000000; font-family: Arial; font-size: 13px;">Date 
    of Birth:</span></div>
<input id="dob" autocomplete="off" name="dob" style="position: absolute; left: 101px; top: 75px; width: 198px; height: 23px; line-height: 23px; z-index: 5;" type="date" value="">

<div id="wb_Text4" style="position: absolute; left: 10px; top: 105px; width: 81px; height: 16px; z-index: 6; text-align: left;">
    <span style="color: #000000; font-family: Arial; font-size: 13px;">Message:</span></div>
<input id="message" autocomplete="off" name="message" style="position: absolute; left: 101px; top: 105px; width: 198px; height: 23px; line-height: 23px; z-index: 7;" type="text" value="">

<input id="Button1" name="" style="position: absolute; left: 101px; top: 135px; width: 96px; height: 25px; z-index: 8;" type="submit" value="Send">
<input id="Button2" name="" style="position: absolute; left: 207px; top: 136px; width: 96px; height: 25px; z-index: 9;" type="reset" value="Reset">
</form>

和“single2.php”如下:

<div id="wb_Text1" style="position: absolute; left: 428px; top: 514px; width: 515px; height: 391px; text-align: center; z-index: 29;">

<?php echo $_POST["name"];  ?>  
</strong></span><span style="color: #000000; font-family: Chancellor; font-size: 19px;">
<br><br>
Local Origin of Name:&nbsp; Unique and Original<br>From the name 
<?php echo $_POST["name"];?>
<br>
<br>
Evaluation Meaning:&nbsp; Festive, Joyous
<br>
<br>
<strong>&#0042;</strong> Emotional Spectrum <strong>&#0042;</strong>
<br>
Up front and honest
<br>
<strong>&#0042;</strong> Personal Integrity <strong>&#0042;</strong>
<br>
Friends know that 
<?php echo $_POST["name"]; ?> 
can be called on in a crisis. <br><strong>&#0042;</strong> Personality <strong>&#0042;</strong>
<br>Life in the fast lane, tempered by common sense. <br><strong>&#0042;</strong>&nbsp; 
Relationships <strong>&#0042;</strong> <br>Stays true and loyal <br><br>
</span></div>

<?php //following for debug
echo 'Name is : '.$_POST["name"].'<br>'; 
echo 'Gender is : '.$_POST["gender"].'<br>'; 
echo 'Date of Birth is : '.$_POST["dob"].'<br>'; 
echo 'Message is : '.$_POST["message"].'<br>'; 
?>