PHP fwrite 错误

发布于 2025-01-04 12:07:30 字数 2629 浏览 1 评论 0原文

我被困住了。一直在努力解决这个问题。这个例子几乎与老师相同......我不明白......html是 这里。其简单的时间表设置。它不会正确写入文件。帮助?

编辑:它不会将变量写入文件。我可以让它写入文本,但不能写入变量。希望能澄清。

<?php

    /* Create folder for data */
    if (is_dir('schedule'))
    chdir('schedule');
    else
    {mkdir('schedule');
     chdir ('schedule');}

    /* Variable Declaration */
    /* Employee 1 */
    $sunStart1=$_POST['sunStart1'];
    $sunEnd1=$_POST['sunEnd1'];
    $monStart1=$_POST['monStart1'];
    $monEnd1=$_POST['monEnd1'];
    $tuesStart1=$_POST['tuesStart1'];
    $tuesEnd1=$_POST['tuesEnd1'];
    $wedStart1=$_POST['wedStart1'];
    $wedEnd1=$_POST['wedEnd1'];
    $thurStart1=$_POST['thurStart1'];
    $thurEnd1=$_POST['thurEnd1'];
    $friStart1=$_POST['friStart1'];
    $friEnd1=$_POST['friEnd1'];
    $satStart1=$_POST['satStart1'];
    $satEnd1=$_POST['satEnd1'];

    /* Employee 2 */
    $sunStart2=$_POST['sunStart2'];
    $sunEnd2=$_POST['sunEnd2'];
    $monStart2=$_POST['monStart2'];
    $monEnd2=$_POST['monEnd2'];
    $tuesStart2=$_POST['tuesStart2'];
    $tuesEnd2=$_POST['tuesEnd2'];
    $wedStart2=$_POST['wedStart2'];
    $wedEnd2=$_POST['wedEnd2'];
    $thurStart2=$_POST['thurStart2'];
    $thurEnd2=$_POST['thurEnd2'];
    $friStart2=$_POST['friStart2'];
    $friEnd2=$_POST['friEnd2'];
    $satStart2=$_POST['satStart2'];
    $satEnd2=$_POST['satEnd2'];

    /* Make data file */
    $schedule = fopen('schedule.txt', 'w');
    fwrite($schedule, "$sunStart1\n");
    fwrite($schedule, "$sunEnd1 \n");
    fwrite($schedule, "$monStart1 \n");
    fwrite($schedule, "$monEnd1 \n");
    fwrite($schedule, "$tuesStart1 \n");
    fwrite($schedule, "$tuesEnd1 \n");
    fwrite($schedule, "$wedStart1 \n");
    fwrite($schedule, "$wedEnd1 \n");
    fwrite($schedule, "$thurStart1 \n");
    fwrite($schedule, "$thurEnd1 \n");
    fwrite($schedule, "$friStart1 \n");
    fwrite($schedule, "$friEnd1 \n");
    fwrite($schedule, "$satStart1 \n");
    fwrite($schedule, "$satEnd1 \n");
    fwrite($schedule, "$sunStart2 \n");
    fwrite($schedule, "$sunEnd2 \n");
    fwrite($schedule, "$monStart2 \n");
    fwrite($schedule, "$monEnd2 \n");
    fwrite($schedule, "$tuesStart2 \n");
    fwrite($schedule, "$tuesEnd2 \n");
    fwrite($schedule, "$wedStart2 \n");
    fwrite($schedule, "$wedEnd2 \n");
    fwrite($schedule, "$thurStart2 \n");
    fwrite($schedule, "$thurEnd2 \n");
    fwrite($schedule, "$friStart2 \n");
    fwrite($schedule, "$friEnd2 \n");
    fwrite($schedule, "$satStart2 \n");
    fwrite($schedule, "$satEnd2 \n");
    fclose ($schedule);
  ?>

I'm stuck. Been trying to fix this. The example is almost identical to the teachers... I don't get it.... The html is here. Its simple setup for a schedule. It won't write to the file correctly. Help?

EDIT: It won't write the variables to the file. I can get it to write text, just not the variables. Hope that clarifies.

<?php

    /* Create folder for data */
    if (is_dir('schedule'))
    chdir('schedule');
    else
    {mkdir('schedule');
     chdir ('schedule');}

    /* Variable Declaration */
    /* Employee 1 */
    $sunStart1=$_POST['sunStart1'];
    $sunEnd1=$_POST['sunEnd1'];
    $monStart1=$_POST['monStart1'];
    $monEnd1=$_POST['monEnd1'];
    $tuesStart1=$_POST['tuesStart1'];
    $tuesEnd1=$_POST['tuesEnd1'];
    $wedStart1=$_POST['wedStart1'];
    $wedEnd1=$_POST['wedEnd1'];
    $thurStart1=$_POST['thurStart1'];
    $thurEnd1=$_POST['thurEnd1'];
    $friStart1=$_POST['friStart1'];
    $friEnd1=$_POST['friEnd1'];
    $satStart1=$_POST['satStart1'];
    $satEnd1=$_POST['satEnd1'];

    /* Employee 2 */
    $sunStart2=$_POST['sunStart2'];
    $sunEnd2=$_POST['sunEnd2'];
    $monStart2=$_POST['monStart2'];
    $monEnd2=$_POST['monEnd2'];
    $tuesStart2=$_POST['tuesStart2'];
    $tuesEnd2=$_POST['tuesEnd2'];
    $wedStart2=$_POST['wedStart2'];
    $wedEnd2=$_POST['wedEnd2'];
    $thurStart2=$_POST['thurStart2'];
    $thurEnd2=$_POST['thurEnd2'];
    $friStart2=$_POST['friStart2'];
    $friEnd2=$_POST['friEnd2'];
    $satStart2=$_POST['satStart2'];
    $satEnd2=$_POST['satEnd2'];

    /* Make data file */
    $schedule = fopen('schedule.txt', 'w');
    fwrite($schedule, "$sunStart1\n");
    fwrite($schedule, "$sunEnd1 \n");
    fwrite($schedule, "$monStart1 \n");
    fwrite($schedule, "$monEnd1 \n");
    fwrite($schedule, "$tuesStart1 \n");
    fwrite($schedule, "$tuesEnd1 \n");
    fwrite($schedule, "$wedStart1 \n");
    fwrite($schedule, "$wedEnd1 \n");
    fwrite($schedule, "$thurStart1 \n");
    fwrite($schedule, "$thurEnd1 \n");
    fwrite($schedule, "$friStart1 \n");
    fwrite($schedule, "$friEnd1 \n");
    fwrite($schedule, "$satStart1 \n");
    fwrite($schedule, "$satEnd1 \n");
    fwrite($schedule, "$sunStart2 \n");
    fwrite($schedule, "$sunEnd2 \n");
    fwrite($schedule, "$monStart2 \n");
    fwrite($schedule, "$monEnd2 \n");
    fwrite($schedule, "$tuesStart2 \n");
    fwrite($schedule, "$tuesEnd2 \n");
    fwrite($schedule, "$wedStart2 \n");
    fwrite($schedule, "$wedEnd2 \n");
    fwrite($schedule, "$thurStart2 \n");
    fwrite($schedule, "$thurEnd2 \n");
    fwrite($schedule, "$friStart2 \n");
    fwrite($schedule, "$friEnd2 \n");
    fwrite($schedule, "$satStart2 \n");
    fwrite($schedule, "$satEnd2 \n");
    fclose ($schedule);
  ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↙厌世 2025-01-11 12:07:30

您的表单方法语法不正确...

<form action="lab5.php" method"POST">

应该是

<form action="lab5.php" method="POST">

加上您的表单结构也不正确...

我会将

放在 之前 并在

之后结束

Your forms method is not syntaxed correctly...

You have

<form action="lab5.php" method"POST">

It should be

<form action="lab5.php" method="POST">

Plus your form structure is also not correct...

I would place the <form> before the <table> and subsequenctly end </form> after </table>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文