Using fwrite with $_POST variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Damian2020
Forum Newbie
Posts: 10
Joined: Thu Aug 20, 2009 5:25 am

Re: Using fwrite with $_POST variables

Post by Damian2020 »

Notice: Undefined index: company_body ... on line 9

Warning: fopen(777) [function.fopen]: failed to open stream: Permission denied ... on line 11

can't open file

Lol same thing. Chmoding? Maybe I misunderstood?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Using fwrite with $_POST variables

Post by jackpf »

No, chmod the file to 777. Are you on windows or *nix? And are you doing this over ftp?
Damian2020
Forum Newbie
Posts: 10
Joined: Thu Aug 20, 2009 5:25 am

Re: Using fwrite with $_POST variables

Post by Damian2020 »

I'm on Windows, FTP yes.

chmod?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Using fwrite with $_POST variables

Post by jackpf »

Your server is running windows? Windows default permissions should allow you to write to the file...

In your FTP client, if you right click the file, do you see "chmod" or "permissions" or something?
Damian2020
Forum Newbie
Posts: 10
Joined: Thu Aug 20, 2009 5:25 am

Re: Using fwrite with $_POST variables

Post by Damian2020 »

Ok I see what you mean. I've enabled all of the write permissions and it's now set to 777.

I'm still getting this message:

Notice: Undefined index: company_body in ... file.php on line 9

My PHP code currently looks like this:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);

//if ($_POST['sendRequest'] == "update_company_page") { // commented out

$company_body = $_REQUEST['company_body'];
$companyFile = "company.txt";
$companyFh = fopen($companyFile, 'w') or die("can't open file");
$companyString = $company_body;
fwrite($companyFh, $companyString);
fclose($companyFh);
?>
Damian2020
Forum Newbie
Posts: 10
Joined: Thu Aug 20, 2009 5:25 am

Re: Using fwrite with $_POST variables

Post by Damian2020 »

I've managed to write the file using a simple string. So it definately works.

It seems the problem lies with getting the $_POST data into the fwrite function.

Is there a way to convert the data to a string maybe? What I've done obviously doesn't work $companyString = $company_body in fact I think it's probably redundant.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Using fwrite with $_POST variables

Post by jackpf »

Are you running this from flash now?
Post Reply