Page 1 of 1

Anyone of you can help me: Form handling, write to File

Posted: Sat Dec 26, 2009 12:20 am
by FranzS
sorry im a total noob to php and i am running in circles trying to get this to work. i basically followed http://www.tizag.com/phpT/filewrite.php and put an "a" instead of "w" . but when the php is called after the form is submitted i get a "can't open file" on my browser and the file im trying to write to(registry.txt) is completely unedited... no clue what's wrong, can anyone tell me please? Many thanks

"form.processed.php":

Code: Select all

<?php
            $myFile="registry.txt";
 
            $fh        =fopen($myFile, 'a') or die("can't open file");
            $stringData=$_GET['FirstName'];
            fwrite($fh, $stringData);
            $stringData=$_GET['LastName'];
            fwrite($fh, $stringData);
            $stringData=$_GET['Email'];
            fwrite($fh, $stringData);
            $stringData=$_GET['Company'];
            fwrite($fh, $stringData);
            $stringData=$_GET['Phone'];
            fwrite($fh, $stringData);
            $stringData=$_GET['City'];
            fwrite($fh, $stringData);
            $stringData=$_GET['State\n'];
            fwrite($fh, $stringData);
            fclose ($fh);
?>
The html form that forwards the info seems to work but here it is anyways("formCheck" is my validation Javascript):

Code: Select all

<form action="form.processed.php" name="formcheck" onsubmit="return formCheck(this);">
<table border=0>
<tr>
    <td>First Name*: </td><td><input type=text name="FirstName" size="30"></td>
</tr>
<tr>
    <td>Last Name*: </td><td><input type=text name="LastName" size="30"></td>
</tr>
<tr>
    <td>E-mail*:</td><td><input type=text name="Email" size="30"></td>
</tr>
<tr>
    <td>Company:</td><td><input type=text name="Company" size="30"></td>
</tr>
<tr>
    <td>Phone:</td><td><input type=text name="Phone" size="30"></td>
</tr>
<tr>
    <td colspan=2>Address</td>
</tr>
<tr>
    <td>City:</td><td><input type=text name="City" size="15">State:<input type=text name="State" size="2"></td>
</tr>
</table>
 
 
 
<input type=submit value="Submit and Download Trial">
</form>
*Required Fields<br><br><br>
 

Re: Anyone of you can help me: Form handling, write to File

Posted: Sat Dec 26, 2009 4:12 am
by mellowman
have u changed the CHMOD?...and if u dont know what that is.. its the setting on the folder that lets you do stuff to it like write stuff and execute files

Re: Anyone of you can help me: Form handling, write to File

Posted: Sat Dec 26, 2009 4:19 am
by cpetercarter
This may be a permissions problem.

fopen($myfile, 'a') will open $myfile if it exists, or create $myfile if it does not exist. But php cannnot do either of these unless $myfile and the directory in which it is located have appropriate permissions. (Do a Google search for 'UNIX permissions' if you are unclear what this means.)

Check the ownership and permissions of the directory in which you want php to create $myfile. FTP programmes can normally do this. You will probably find that it is owned by 'you' (ie your username), and that the permissions are 0755, which means that only 'you' can create new files or amend existing ones within the directory. The problem is that php (or, more strictly, the web server) is not 'you' - it has its own username, which may be 'www-data'. Often, programmers will create a directory with 0777 permissions and use that directory as the location for files which they want php to create.

So, try creating a directory eg 'files' as a subdirectory of the directory where your code is located, and then change the permissions in the 'files' directory to 0777. Then define $myfile as 'files/registry.txt'

Re: Anyone of you can help me: Form handling, write to File

Posted: Sat Dec 26, 2009 4:37 am
by mellowman
Some hosting companies don't allow u to change your chmod through ftp programs so...if ur script continues to fail come back and say so and ill give u idea #2 :mrgreen:or aim me and ill help u out

aim-imcmellowman

Re: Anyone of you can help me: Form handling, write to File

Posted: Sat Dec 26, 2009 4:01 pm
by FranzS
I don't know if its relevant

but a)I'm just a programming minion with ftp access, though i can probably gain access to domain control panel. I ran a phpinfo file and its a Windows System(not unix, did not find anything in phpinfo regarding CHMOD)... Server info is: "Windows NT WEBWIN122 5.2 build 3790". the phpinfo also reads out under PHPCore Configuration: "auto_append_file(Directive) no value(Local Value) no value(Master Value)"

and b)
In ftp i tried right clicking a folder and seeing its properties and besides basic folder info it reads: "This server does not support changing file permissions" so I think i'll have to ask for/do a change in server control panel.

Re: Anyone of you can help me: Form handling, write to File

Posted: Mon Dec 28, 2009 10:14 pm
by FranzS
*bump*