0

I am working on a form that will allow a user to submit text to the website and save it as a file on the server that I can retrieve later. I am using the following form:

    <p>
      <label for="Name">First Name</label>
      <input type="text" name="Name" id="Name" />
    </p>
    <p>
      <label for="Last Name">Last Name</label>
      <input type="text" name="LastName" id="LastName" />
    </p>
    <p>
      <label for="GuideName">Guide Name</label>
      <input type="text" name="GuideName" id="GuideName" />
    </p>
    <p>Copy and paste your study guide into this box.</p>
    <p>
      <textarea name="Guide" id="Guide" cols="100" rows="30"></textarea>
    </p>
    <p>Submit
      <input type="submit" name="Submit" id="Submit" value="Submit" />
      </p>
    </form>

and the following PHP code:

<?php
if (isset($_POST['Submit']))
{
    $firstName = $_POST['Name'];
    $lastName = $_POST['LastName'];
    $guideName = $_POST['GuideName'];
    $guide = $_POST['Guide'];
    $finalGuideName = $guideName."(".$firstName." ".$lastName.").txt";

    $fh = fopen($finalGuideName, 'w') or die("can't open file");
    fwrite($fh, $guide);
    fclose($fh);
}  
?>

I've used this code (at least I think it's this code) in the past to take the user's information and create a text file on the server with it. However, when I got to check to see if the form worked, nothing appears on the server. What am I doing wrong? Thanks in advance.

Thanks for your help everyone, as I was trying to fix it, it started to work again. I have absolutely no idea why, I'm pretty sure I didn't change anything, but thanks again for all your help.

1
  • What happens or doesn't happen? Is the condition ever entered? Commented Dec 15, 2011 at 16:20

3 Answers 3

1

your sumbit button name is Submit2, so use this code

if (isset($_POST['Submit2'])) 
Sign up to request clarification or add additional context in comments.

2 Comments

I realized that right after a I posted and changed the button name to just Submit. Didn't work.
also make sure that your form method is post.....also try to execute the code without if statment and echo all form values....it might help you in finding the problem....
0

You need to make sure the directory you're writing in allows write permissions (change to 0755 or 0644*). Also, I wouldn't recommend writing to the ROOT of the site, make a folder and change the permissions on THAT. It's not a good idea to let anyone write to the root, haha

*Thanks to Lawrence for pointing out my mistake

3 Comments

0777 is a security risk, 0755 or 0644 would suffice
This is true. I'll change my post just in case the OP doesn't read the comments haha
The submit.php file itself is in a folder, so it should write to the root of that folder. 0644 made popped up a page saying it didn't have permissions, 777 made no difference. It keeps defaulting back to 705.
0

have you tried using $_REQUEST instead of _POST or _GET?

to discover furher informations I think you shall also put an else to your

if(isset($_POST['Submit'])) {

just to make sure that the statement is reached. and as a last resort, check you paths and their permissions, like begin with a 0777, and if it works correct it to 755 or 644 (it depends by the cofiguration of the owning user of the directory vs the apache user, they shall be all in the same group, but that's another story )

Comments

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.