Training, Open Source
computer languages


PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
PHP, Basic flat file shout box HELP

Posted by Dbyte (Dbyte), 17 May 2007
Firstly i'd like to say i dont know more than really basic php,
But i have a friend who loves php and he's very sick latly so i was hoping some one here could help me with his code...


its spread across three files

first one is index.php

I could send you the files if you wish just email me digimbyte _at_ gmail _dot_ com
Code:
<?php
$get_shout = fopen('shout/shout.txt',a);
$shout = nl2br($get_shout);
?>

//title and other stuff
//body



<form id="shout" name="shout" method="post" action="shout.php" class="shout">
 <label>
 </label><div style="width: 120px; height:150px; overflow:auto; background: #ffffff"><?php print $shout; ?></div>
 <input name="shout_field" type="text" id="shout_field" value="Shout Here" size="22" class="shout"/>
 </label>
 <label>
 <input name="shout_submit" type="submit" class="shout" id="shout_submit" value="  -:Shout:-  "/>
 </label>
</form>

// i also copied this following part into a shout.php

<?php if($_POST['shout_submit'])

{
$message="
$_POST[shout_field]";
fwrite(fopen('shout/shout.txt',a), $message);
}


?>





shout.php

Code:
<?php
if($_POST['shout_submit'])

{
$message="
$_POST[shout_field]";
fwrite(fopen('shout/shout.txt',a), $message);
}

?>





the other part is the text file

at url 'shout/shout.txt'

to see how it looks now
go to

(some times the images don't load properly, I have no idea why)

http://dbyte.icshost.org/

the text files url is
http://dbyte.icshost.org/shout/shout.txt

the php writes in the file fine but the div doesn't read it for some reason all i get is 'Resource id #3'

thanks in advanced


Posted by admin (Graham Ellis), 17 May 2007
Quote:
<?php
$get_shout = fopen('shout/shout.txt',a);
$shout = nl2br($get_shout);
?>



The code above opens a file for append, then prepares it for output ... however, it's just the file handle.   To read a file, you need to use "r" rather that a in your fopen, then use an fgets (or something similar) to actually read the data.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


WELL HOUSE CONSULTANTS LTD.: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho