Jump to content

Recommended Posts

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)
[code]<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> 
[/code]

this is the retrieval code that works here [url=http://shadowharlequin.awardspace.com/news3.html]http://shadowharlequin.awardspace.com/news3.html[/url]
[code]<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>[/code]

but this code DOESNT work here [url=http://shadowharlequin.freehostia.com/php/new3.html]http://shadowharlequin.freehostia.com/php/new3.html[/url]
[code]<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>[/code]

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!
Link to comment
https://forums.phpfreaks.com/topic/23403-simple-txt-retrievle-in-html-not-working/
Share on other sites

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:

[code]<?php
phpinfo();
?>[/code]

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
on awardspace its here [url=http://shadowharlequin.awardspace.com/ver.php]http://shadowharlequin.awardspace.com/ver.php[/url]
PHP Version 4.4.2

but the other it doesnt work on [url=http://shadowharlequin.freehostia.com/php/ver.php]http://shadowharlequin.freehostia.com/php/ver.php[/url]
[b]/edit:[/b]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 [url=http://shadowharlequin.freehostia.com/php/news3.html]http://shadowharlequin.freehostia.com/php/news3.html[/url]

thanks loads for the speady reply :)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.