donglan8999 2014-07-02 11:23
浏览 41
已采纳

我的php不会创建一个新文件来保存我的表单数据

I wrote some code for a membership form for a church. When the form is submitted, it's supposed to create a new .txt file using the first name of the person filling the form. When I run the code, it works, I don't get an error message but the file doesn't get created. What am I doing wrong??

This is the php I wrote for it

    $Salutation = trim($_POST['salutation']);
    $FirstName = trim($_POST['firstname']);
    $OtherName = ($_POST['othernames']);
    $LastName = trim($_POST['lastname']);
    $Gender = trim($_POST['Gender']);
    $Nationality = trim($_POST['nationality']);
    $DOB = trim($_POST['DOB']);
    $POB = trim($_POST['POB']);
    $Marital_Status = trim($_POST['MarStat']);
    $Occupation = trim($_POST['occupation']);
    $Workplace = trim($_POST['POW']);
    $Residence = trim($_POST['POR']);
    $Children = trim($_POST['Kids']);
    $Postal = trim($_POST['postal']);
    $Telephone = trim($_POST['telephone']);
    $Email = trim($_POST['email']);
    $Diocese = trim($_POST['diocese']);
    $Branch = trim($_POST['branch']);
    $HowLongBornAgain = trim($_POST['lengthBornAgain']);
    $WhenJoinLCI = trim($_POST['WJLCI']);
    $Member_Type = trim($_POST['memtype']);
    $HowFind = trim($_POST['howFind']);
    $Who_Knows_Name = trim($_POST['whoknowname']);
    $Who_Know_Num = trim($_POST['whoknownum']);
    $Who_Know_Rel = trim($_POST['whoknowrel']);

    $data = "Name | $Salutaion $FirstName $OtherName $LastName

            Gender | $Gender

            Nationality | $Nationality

            Date of Birth | $DOB

            Place of Birth | $POB

            Marital Status | $Marital_Status

            Occupation | $Occupation

            Workplace | $Workplace

            Residence | $Residence

            Children | $Children

            Postal Address | $Postal

            Telephone | $Telephone

            E-mail | $Email

            Diocese | $Diocese

            Branch | $Branch

            Years Born Again | $HowLongBornAgain

            When $Salutation $LastName joined LCI | $WhenJoinLCI

            Member Type | $Member_Type

            Found Lighthouse through | $HowFind

            Person Who Knows Member | $Who_Knows_Name

            $Who_Knows_Name \'s number | $Who_Know_Num

            Relationship between the two members | $Who_Know_Rel
":

    $myfile = $Salutaion." ".$FirstName." ".$OtherName." ".$LastName.".txt";

    $create_file = fopen($myfile, w) or die("Can't open file.");
    fwrite($create_file, $data) or die("Couldn\'t write values to file.");

    fclose($create_file);



}
  • 写回答

1条回答 默认 最新

  • doudou348131346 2014-07-02 11:57
    关注

    In ANSWER to the question:

    your $data string has : instead of ; at the end.

    This will cause your php script to fail before even getting to creating the file name.

    Hence no error

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?