0

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);
  ?>
5
  • "It won't write to the file correctly" - Give us a clue?? What is the expected result and what are you getting? Commented Feb 12, 2012 at 22:18
  • Why cant you use a control array? So you dont have to specifically name each control. Commented Feb 12, 2012 at 22:20
  • It doesn't want to write the variables to the file. Commented Feb 12, 2012 at 22:20
  • @craig1231 I honestly don't know what that is. I'm beginning php. This is an assignment for an "Intro to PHP" course. Commented Feb 12, 2012 at 22:21
  • As an aside, the question presumably originally contained your <form> syntax. However now that it has been edited to remove that, new readers can't follow the question. It is usually better to add extra info at the bottom of your question, or to cross things out explicitly :) Commented Feb 12, 2012 at 22:32

1 Answer 1

3

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>

Sign up to request clarification or add additional context in comments.

6 Comments

Everytime. Everytime. Its always something stupid... Thank you so much. If I may ask, did you just skim it to find that? or did you use some sort of scanner to detect errors?
Skimmed it, ive been programming for too long ;) However you could use the validator.w3.org to validate your HTML code ;)
Well thanks for your help. I need to learn to look over stuff like this. I'll check as answer as soon as it lets me.
Do you have any program suggestions. I used to use HTML kit because it was free and I'm a poor college student lol.
I would recommend Netbeans, thats free ;)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.