Simple PHP Question

Discussion in 'Web Design and Development' started by steve1717, Jul 18, 2007.

  1. steve1717 macrumors newbie

    Joined:
    Jul 18, 2007
    #1
    I've turned one of my Macs into a web server and have successfully got Apache and PHP running. What I can't seem to figure out is how to use PHP to take the contents of a simple HTML form and save them to a text file. Could anyone kindly point me in the right direction? I've read many example scripts of how to do this but none seem to pertain directly to a Mac web server.:confused:
     
  2. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #2
    what do you mean by "mac web server"? osx comes w/ apache, which works very well with php. so what is it about your example scripts that doesn't apply?
     
  3. steve1717 thread starter macrumors newbie

    Joined:
    Jul 18, 2007
    #3
    Simple PHP Question

    I have both Apache and PHP on. Trouble is, I can't get the PHP script to save very simple output in the Library/WebServer/Documents folder where the scripts are stored (I have already given the folder 777 read-write permissions). These are the 2 scripts -- in the case below, I get a file called "file.txt" but it has nothing in it. Any idea what I am doing wrong?

    HTML:

    <form action="save.php" method="POST">
    <textarea name="content"></textarea>
    <br>
    <input type="submit" value="Save">
    </form>

    PHP:

    <?
    $content = $_POST['content'];
    $file = "file.txt";
    $Saved_File = fopen($file, 'w');
    fwrite($file, $content);
    fclose($file);
    ?>
     
  4. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #4
    how about some error checking? see example 637.

    have you dumped $content to the screen to see if there's anything there? you need to debug!
     

Share This Page