Jump to content


Photo

Simple txt retrievle in html not working!


  • Please log in to reply
2 replies to this topic

#1 ShadowHarlequin

ShadowHarlequin
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 October 2006 - 08:44 AM

ive been trying to find some free hosting since my friends went down and i found a couple but favoured one over the other as the images dont always work on the 1st one

i uploaded this script to both servers and it simply places text from a form into a .txt file and retrieves it for display in a html document, it works on the 1st server just not on the one id prefer to use and was wondering if the code has somethign wrong

this is the posting script that DOES work on both sites (posts form to .txt file)
<STYLE TYPE='text/css'>
BODY{background-color:#333333; font-family:sans-serif; font-size:xsmall; } </STYLE>
<?
//this should all go into one file. I would name it addnews.php
if($HTTP_POST_VARS['submit']) {
{
        if(!$HTTP_POST_VARS['name']) {
            echo "You must enter a topic";
            exit;
        }
        if(!$HTTP_POST_VARS['news']) {
            echo "You must enter a bitch or moan";
            exit;
        }
        if(strstr($HTTP_POST_VARS['name'],"|")) {
            echo "Topic cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['news'],"|")) {
            echo "Your bitch/moan cannot contain the pipe symbol - |";
            exit;
        }
        $fp = fopen('news.txt','a');
        if(!$fp) {
            echo "Error opening file!";
            exit;
        }
        $line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
        $line .= "|" . $HTTP_POST_VARS['news'];
        $line = str_replace("\r\n","<BR>",$line);
        $line .= "\r\n";
        fwrite($fp, $line);
        if(!fclose($fp)) {
            echo "Error closing file!";
            exit;
        }        
    } 
}

?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
<font color='#dddddd' size='xsmall'>What is pissing me off is:</font><BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
<font color='#dddddd' size='xsmall'>Bitch and Moan here:</font><BR>
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>

<INPUT TYPE="submit" NAME="submit" VALUE="Rant and Rave!"><BR>
</FORM>  

this is the retrieval code that works here http://shadowharlequ....com/news3.html
<STYLE TYPE='text/css'>
BODY{background-color:#333333; font-family:sans-serif; font-size:xsmall; } </STYLE>

<body>
<?php>
$data = file('news.txt');
$data = array_reverse($data);
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
    echo "<font color='#dddddd' size='xsmall'><b>Posted on: </b>" . $pieces[0] . "<br><b>Topic:</b> " . $pieces[1] . " <BR></b><i>" .  $pieces[2] . "</i><BR><BR></font>";
}
?></body>

but this code DOESNT work here http://shadowharlequ...m/php/new3.html
<STYLE TYPE='text/css'>
BODY{background-color:#333333; font-family:sans-serif; font-size:xsmall; } </STYLE>

<body>
<?php
$data = file('news.txt');
$data = array_reverse($data);
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
    echo "<font color='#dddddd' size='xsmall'><b>Posted on: </b>" . $pieces[0] . "<br><b>Topic:</b> " . $pieces[1] . " <BR></b><i>" .  $pieces[2] . "</i><BR><BR></font>";
}
?>
</body>

its pretty beyond me wat the problem is, and both servers offer php etc (i can install other scripts on freehostia so this should work)

any help appreciated thanks all!

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 09 October 2006 - 08:48 AM

If it works on one but not the other, it would appear it's a configuration issue.

Create a php file that looks like this:

<?php
phpinfo();
?>

Then upload it to both servers and run it, it should give you the version of php.

Check your functions for incompatibilities, I'd be interested to see if the fopen() and fwrite() functions were working the same on both servers.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 ShadowHarlequin

ShadowHarlequin
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 October 2006 - 09:03 AM

on awardspace its here http://shadowharlequ...ace.com/ver.php
PHP Version 4.4.2

but the other it doesnt work on http://shadowharlequ...com/php/ver.php
/edit:oh that DOES work  now and its 4.3.2 or seomthing so i guess i needed that down there V for it to work?

however i added a line to the .htaccess file i read that parses html as php and now i think it works properly http://shadowharlequ.../php/news3.html

thanks loads for the speady reply :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users