SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    News Script Help please =)

    PHP Code:
     }
            
    $line date("m.d.y") . "|" $HTTP_POST_VARS['name'];
            
    $line .=  "|" "<b>" $HTTP_POST_VARS['topic'].":</b><p><hr>";
            
    $line .= "<img src=" $HTTP_POST_VARS['avatar'] . ">" "&nbsp;&nbsp;";
            
    $line .= "|" $HTTP_POST_VARS['news']."<p><hr>";
            
    $line =  str_replace("\r\n","<BR>",$line);
            
    $line .= "\r\n";
            
    fwrite($fp$line);
            if(!
    fclose($fp)) {
                echo 
    "Error closing file!";
                exit; 
    The "news" variable isn't working, because it will show everything else on the news page, topic, avatar, name, but not the actual news. Could you perhaps help me find my syntax error.

    The line im having trouble with (I think) is

    PHP Code:
     $line .= "|" $HTTP_POST_VARS['news']."<p><hr>"
    Thanks =)

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried just echo'ing out the $HTTP_POST_VARS['news'] variable? Does it just come up blank?
    Paul Davey
    webmaster for Whitford Church of Christ

  3. #3
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good Idea.. Let me try that.

  4. #4
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesnt work. =/

    Edit: I enclosed a zip file with the entire script and what not..
    Attached Files Attached Files

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you be a bit more specific. Does it give an error, or just print a blank? If it prints a blank, then the variable has not been set, and I would check you have the correct POST variable name that corresponds to the HTML form. I can't see any errors in your code sample.
    Paul Davey
    webmaster for Whitford Church of Christ

  6. #6
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok It prints all the variables on the the actual news displayp page but fails to print the text that was typed in the news form field.

  7. #7
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     <font face="Tahoma" size="2">
    <?
    //This code is the expressed property of Liquid Fridge(c)
    include('include/header.inc');
    if(
    $HTTP_POST_VARS['submit']) {
    if(
    $HTTP_POST_VARS['password'] == '600408') {
    if(!
    $HTTP_POST_VARS['name']) {
    echo 
    "You must enter a name";
    exit;
    }
    if(!
    $HTTP_POST_VARS['news']) {
    echo 
    "You must enter some news";
    exit;
    }
    if(
    strstr($HTTP_POST_VARS['name'],"|" )) {
    echo 
    "Name cannot contain the pipe symbol - |";
    exit;
    }
    if(
    strstr($HTTP_POST_VARS['news'],"|" )) {
    echo 
    "News cannot contain the pipe symbol - |";
    exit;
    }
    $fp fopen('data/news.txt','a');
    if(!
    $fp) {
    echo 
    "Error opening file!";
    exit;
    }
    $line date("m.d.y" ) . "|" $HTTP_POST_VARS['name'];
    $line .= "|" "<b>" $HTTP_POST_VARS['topic'].":</b><p><hr>";
    // $line .= "<img src=" . $HTTP_POST_VARS['avatar'] . ">" . "&nbsp;&nbsp;";
    $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;
    }
    } else {
    echo 
    "Bad Password";
    }
    }
    ?>
    <FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
    Your name:<BR>
    <INPUT TYPE="text" SIZE="30" NAME="name"><BR>
    Your avatar's URL: <BR> "generic.jpg" without the quotes if you do not have one<BR>
    <INPUT TYPE="text" SIZE="30" NAME="avatar"><BR>
    The Topic:<BR>
    <INPUT TYPE="text" SIZE="30" NAME="topic"><BR>
    The News: <BR>
    <TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
    News Password:<BR>
    <INPUT TYPE="password" SIZE="30" NAME="password"><BR>
    <INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
    </FORM>
    <?
    include('include/footer.inc');
    ?>
    </font>
    Thats the code for the news page.

    The news display page's code is:
    PHP Code:
    html>
    <head>
    <title>News Display Code</title>
    </head>
    <body>
    <?PHP
    $data 
    file('data/news.txt');
    $data array_reverse($data);
    foreach(
    $data as $element) {
    $element trim($element);
    $pieces explode("|"$element);
    echo 
    $pieces[2] . "<BR>" "<b>Posted by " $pieces[1] . " on " $pieces[0] . "</b><BR><BR>";
    }
    ?>
    </body>
    </html>
    Does this help any?

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume it gets past this line okay:
    PHP Code:
    <?php
    if(!$HTTP_POST_VARS['news']) {
    echo 
    "You must enter some news";
    exit;
    ?>
    Which means that the 'news' variable contains something. I can't think of anything else to try - I tried your code and it worked for me.
    Paul Davey
    webmaster for Whitford Church of Christ

  9. #9
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok.. Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •