php输出中不显示文本输入数据

时间:2013-09-18 13:15:48

标签: php html

我正在尝试创建简单的脚本,其中文本输入数据将通过php.Html部分工作正常存储在文本文件中但PHP代码未显示任何输出,并且没有任何内容写入文本文件。这是我的代码, HTML部分

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Untitled Document</title>
        <LINK REL="Stylesheet" TYPE ="text/css" HREF="info.css">
    </head>

    <body>
        <form style="" method="post"   action="personalinfo.php">
           <label for="inputname">Name:</label><input id ="inputname" name="iname" input type="text"/>
           <br/>
           <br/>

           <label for=""="inputaddress">Address:</label><input id="inputaddress" name="iaddress" INPUT type="text"/>
           <br/>
           <br/>
           <label for="inputcity">City:</label><input id="inputcity" name="icity" type="text" />
           <br/>
           <br/>
           <label for="inputstate">State:</label><input id="inputstate" name="istate" type="text" />
           <br/>
           <br/>
           <label for="inputzip">Zip Code:</label><input id="inputzip" name="izip" type="text" />
          <br/>
          <br/> 
          <input type="submit" name="submit" value="Submit"/>
        </form>
    </body>
</html>

PHP代码

<html>
    <body>
        <?php
            if (isset($_POST['iname']))
            {
                $name=$_POST['iname'];
                $address =$_POST['iaddress'];
                $city =$_POST['icity']; //the data
                $state=$_POST['istate'];
                $zip=$_POST['izip'];
                $data= "$name|$address|$city|$state|$zip \n";

                //open the file and choose the mode
                $fh = fopen("pinfo.txt", "a");

                fwrite($fh, $data); 

                fclose($fh);
                print '$name';
            }
            ELSE
            {
                PRINT"NOThing";
            }
        ?>
    </body>
</html>

2 个答案:

答案 0 :(得分:1)

问题在于您的

FROM

<label for="inputname">Name:</label><input id ="inputname" name="iname" input type="text"/>

<label for="inputname">Name:</label><input id ="inputname" name="iname" type="text"/>

删除输入关键字,它只需要与<input关联,您使用它两次。

答案 1 :(得分:0)

删除输入,将其更改为

<label for="inputname">Name:</label><input id ="inputname" name="iname" type="text"/>

我在你的php代码中做了一些改动

<html>
<body>
<?php
if(isset($_POST['submit'])) {
    //print_r($_POST);  
    $name=$_POST['iname'];
    $address =$_POST['iaddress'];
    $city =$_POST['icity']; //the data
    $state=$_POST['istate'];
    $zip=$_POST['izip'];

    $data = $name."|".$address."|".$city."|".$state."|".$zip;

    //open the file and choose the mode

    $fh = fopen("pinfo.txt", "a");
    print_r($_POST);
    fwrite($fh, $data); 
    fclose($fh);    
}
else {
    echo "Nothing";
}
?>
</body>
</html>

它会正常工作。从http://www.w3schools.com/

学习一些PHP基础知识