Jump to content

Need help with Server-side Text File editing


ThatBurritoGuy

Recommended Posts

Hello! First post here.

I made an "interview" webpage. Basically just the typical Question then Textbox thing. I think it'll be more clear if I posted the code.

<html>
<title> PHP </title>
<head>
</head>
<body>
<form name="form1" method="POST" action="TestProcess.php">
What is your name on Facebook?<br>
<input type="text" size=100 name="Question1"><br>
<br>
Why do you deserve to be an admin?<br>
<input type="text" size=100 name="Question2"><br>
<br>
Do you have any past experiences of being an administrator? Yes or No?<br>
<input type="text" size=100 name="Question3"><br>
<br>
What are your skills?<br>
<input type="text" size=100 name="Question4"><br>
<br>
What about your managing skills, how is it? Rate it 1-10<br>
<input type="text" size=100 name="Question5"><br>
<br>
Why should we choose YOU over the other applicants?<br>
<input type="text" size=100 name="Question6"><br>
<br>
Are you active? How much?<br>
<input type="text" size=100 name="Question7"><br>
<br>
<br>
<br>
<br>
<input type="Submit" name="Submit1" value="Submit">
</form>
</body>
</html>

Now that should be easy, it's just those "<br>" tags that expand it lol.

Here's the TestProcess.php
 

<?php
$q1=$_POST['Question1'];
$q2=$_POST['Question2'];
$q3=$_POST['Question3'];
$q4=$_POST['Question4'];
$q5=$_POST['Question5'];
$q6=$_POST['Question6'];
$q7=$_POST['Question7'];
$fn="TestPHPAnswers.txt";
$file=fopen($fn, "a+");
fwrite($file, $q1."/n".$q2."/n".$q3."/n".$q4."/n".$q5."/n".$q6."/n");
fclose($file);
print("Application Sent");
?>

By looking at the code, you'll realize I have 3 pages for my site.

The concept I have in mind is:

1. Users fill out textboxes. These textboxes have specific names.

2. The values of the textboxes are assigned to variables.

3. The TestProcess opens a text file in the site (more on this later, I'm a bit confused.) and appends the variables to it, then close.

That's it. Now, when I tried to run my code, went through everything. I was surprised that the text file is untouched. No modifications or anything. Does it have something to do with the "$fn" part? Should I do "www.example.com/TestPHPAnswers.txt" or just "TestPHPAnswers.txt"?

 

I also tried the "file_put_content" thing, still didn't work. Can someone tell me what's wrong? and maybe, nudge me into the right solution?  Thanks :D


(Anyways, I just started PHP two days ago. Pretty sure I'm missing out on something.)

Link to comment
Share on other sites

Its late for me but the code looks ok...

Well... \n not /n, and <br /> not <br>... but...

 

 

Have you tried directly trying to write the file:

 

error_reporting(E_ALL);
ini_set('display_errors',E_ALL);
 
$file=fopen($fn, "a+");
fwrite($file, "my test\n");
fclose($file);

 

This way you'll see any errors generated.

My first thought would be file permissions...

Link to comment
Share on other sites

Is a lot of checking you should be doing but you can get to that later.

 

One thing is these results should be saving to one line and using a delimiter

fwrite($file, $q1."||".$q2."||".$q3."||".$q4."||".$q5."||".$q6."\r\n");

When you go to read the file the array will be each line, then you explode by the delimiter to get each value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.