Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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.

You can Add a comment or ranking to this page

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