Google Community Chat
 
I need help with this bit of code - php

You're visiting Google Community as a guest.
In order to post, you'll need to register and log in.


(If you were registered and logged in, these advertisements wouldn't be here)
Post new topic   Reply to topic    Google Community Forum Index // Web Design, Coding & Programming Forum
   
Author Message
pleasant
Senior Googler
Senior Googler


Joined: 31 Jul 2004
Location: australia
1094.80 GC$

Items

PostPosted: Sun Oct 24, 2004 10:59 pm    Post subject: I need help with this bit of code - php Reply with quote
this code is for a page for staff on my site to use to edit some pages.
Code:
<?php
$handle = fopen("downloads.html", "r");

?>
<?php
$filename = 'downloads.html';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
 
   echo "Success, wrote ($somecontent) to file ($filename)";
 
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>



<?php

  $handle = fopen('downloads.html', 'r');
 
  fclose($handle);
 
?>


instad of it just adding "Add this to the file"
i want a box to come up and they write what ever they want into it.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
zirias
Noogle
Noogle


Joined: 24 Oct 2004
Location: Germany
858.60 GC$

Items

PostPosted: Mon Oct 25, 2004 7:58 am    Post subject: Reply with quote
Just do something like
Code:
$somecontent = $_POST['somecontent']
if ($somecontent=="") {
  echo '<form method="post" action="'.$PHP_SELF.'">
    <textarea name="somecontent"></textarea>
  </form>
  ...';
} else {
  // rest of your script
}


Greets, Felix
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number
pleasant
Senior Googler
Senior Googler


Joined: 31 Jul 2004
Location: australia
1094.80 GC$

Items

PostPosted: Mon Oct 25, 2004 9:39 pm    Post subject: Reply with quote
i get an undexpected T_IF on line 8 this is what i put just incase i put it in the worng place:
Code:
<?php
$handle = fopen("downloads.html", "r");

?>
<?php
$filename = 'downloads.html';
$somecontent = $_POST['somecontent']
if ($somecontent=="") {
  echo '<form method="post" action="'.$PHP_SELF.'">
    <textarea name="somecontent"></textarea>
  </form>
  ...';
} else {
  // rest of your script
}

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
 
   echo "Success, wrote ($somecontent) to file ($filename)";
 
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>



<?php

  $handle = fopen('downloads.html', 'r');
 
  fclose($handle);
 
?>

_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
intelliot
Site Admin


Joined: 01 May 2004

18653.45 GC$

Items

PostPosted: Mon Oct 25, 2004 9:40 pm    Post subject: Reply with quote
Just use a standard HTML form. You are missing a semicolon in your code.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
zirias
Noogle
Noogle


Joined: 24 Oct 2004
Location: Germany
858.60 GC$

Items

PostPosted: Tue Oct 26, 2004 1:24 am    Post subject: Reply with quote
That was example code. Not tested and "..." means anything you like to complete your HTML output. In the first line, I forgot the ";". Hey, I thought you knew PHP ... don't you?

Greets, Felix
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number
jose.mira
Noogle
Noogle


Joined: 22 Oct 2004
Location: Portugal
741.35 GC$

Items

PostPosted: Wed Oct 27, 2004 5:38 pm    Post subject: Reply with quote
you are missing the semicolon in line 7:
Quote:
$somecontent = $_POST['somecontent']

that's why you get an error in line 8 Very Happy
_________________
Back to top
View user's profile Send private message Visit poster's website
pleasant
Senior Googler
Senior Googler


Joined: 31 Jul 2004
Location: australia
1094.80 GC$

Items

PostPosted: Sun Oct 31, 2004 2:08 am    Post subject: Reply with quote
it just says that downloads.html is not writable but it is
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
zirias
Noogle
Noogle


Joined: 24 Oct 2004
Location: Germany
858.60 GC$

Items

PostPosted: Sun Oct 31, 2004 3:22 am    Post subject: Reply with quote
I don't think this is a PHP related problem. If your script runs on a multiuser system, the file has to be writable for the user running the webserver. On many linux-systems, you can use the group "www-data".

Greets, Felix
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number
Ashes
Senior Googler
Senior Googler


Joined: 26 Sep 2004
Location: Bosom of Dixie
1601.05 GC$

Items

PostPosted: Sun Oct 31, 2004 5:34 am    Post subject: Reply with quote
You probably need to chmod the file to 777.
_________________
This is a sig. Isn't it nice?
pushing through [dot] com
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger ICQ Number
zirias
Noogle
Noogle


Joined: 24 Oct 2004
Location: Germany
858.60 GC$

Items

PostPosted: Sun Oct 31, 2004 5:46 am    Post subject: Reply with quote
Ashes wrote:
You probably need to chmod the file to 777.


No, you don't. You don't want to make files world-writable. Group-writable (770) is already bad enough. Change group to the webserver's group.

The better solution would be to use a database.

Greets, Felix
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number
Sponsored Links
Posted: 5 Dec 2008 9:06 am    Post subject: Advertisements
Back to top
Post new topic   Reply to topic    Google Community Forum Index // Web Design, Coding & Programming Forum All times are GMT - 8 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Host your free forums with Invision Plus.net forum web hosting with your own subdomain.

alexisBlue v1.2 // Theme Created By: Andrew Charron // Icons in Part By: Travis Carden

© 2005-2006 Google Community

Powered by phpBB

Privacy Policy | Contact Us

Powered by Google Search blog

This website is not affiliated in any way with Google, Inc.
Google™ is a registered trademark of Google, Inc.