0

我正在尝试创建简单的脚本,其中文本输入数据将通过 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>
4

2 回答 2

1

问题出在你的

<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关键字,只需要 with <input,你用了两次。

于 2013-09-18T13:20:40.740 回答
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 基础知识

于 2013-09-18T13:41:31.840 回答