Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Footer not showing until php script executes

    Hi,

    It seems my footer will not display until the script has excuted, I've moved it around various places in the code to no avail.

    Here's the code:

    Code:
    <?
    include "db_con.php";
    include "header.php";
    ?>
    <html>
    <head>
    <? $title = "Add News"; ?>
    <title><? echo "$title - RogueLayeredTechnologies" ?></title>
    </head>
    <? echo "<br><br>Add news directly to the homepage using this form.<br><br>"; ?>
    <form action="<? $PHP_SELF; ?>" method="post"> 
    <b>Title</b> 
    <BR /> 
    <input type="text" name="title" size="40" maxlength="50" value="" /> 
    <br /> 
    <br />
    <b>Date</b><BR><textarea name="date" rows="2" cols="40"></textarea> 
    <br /> 
    <br /> 
    <b>News</b><BR><textarea name="news" rows="3" cols="40"></textarea> 
    <br /> 
    <br />
    <b>Password</b><BR><input type="password" name="password"> 
    <br /> 
    <br /> 
    <input type="submit" value="submit" name="submit" /> <input type="reset" value="reset" /> 
    </form>
    </html>
    <?
    /*function make_clickable($text) 
    { 
    $ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\2\3\" target=\"_blank\" target=\"_new\">\1://\2\3</a>", $text); 
    $ret = eregi_replace( "(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\1\" target=\"_new\">\\1</a>", $ret); 
    return($ret); 
    }*/ 
    /*function BBCODE($bbcode) 
    { 
    //the bbcode tags.. 
    $bbc_a=array("[str]","[/str]","","","","","[big]","[/big]","[huge]","[/huge]","","","","","[red]","[/red]","[orange]","[/orange]","[green]","[/green]","[blue]","[/blue]"); 
    
    //bbcode gets converted to.. 
    $bbc_b=array("<strike>","</strike>","<b>","</b>","<u>","</u>","<font size=4>","</font>","<font size=8>","</font>","<a href=\"mailto:","\">E-MAIL LINK</a>","<a href=\"","\" target=\"blank\">WEB LINK</a>","<font color=#ff6666>","</font>","<font color=#ffaa66>","</font>","<font color=#66ff66>","</font>","<font color=#6666ff>","</font>"); 
    
    $bbc_num=count($bbc_a); 
    $loop=0; 
    while($loop<$bbc_num) 
    { 
    $bbcode=str_replace($bbc_a[$loop], $bbc_b[$loop], $bbcode); 
    $loop++; 
    } 
    return $bbcode; 
    } */ 
    
    if (!$_POST['submit']){ 
    die(); 
    } 
    if (($_POST['password']) != ("admin")){ 
    echo "Wrong Password"; 
    die(); 
    } 
    if (!$_POST['title'] || !$_POST['news']){ 
    echo "You forgot to enter a title or news!"; 
    die(); 
    }  
    $addnews = mysql_query("INSERT INTO news VALUES ('NULL', '$_POST[title]', '$_POST[date]', '$_POST[news]')"); 
    echo "News has been successfully added to the database, it will now appear on the <a href='./index.php' class='Main'>homepage</a>.<br><br>"; 
    
    ?>
    <?
    include "footer.php";
    include "analytics.php";
    ?>
    May be something simple yet I can't figure it out. If I put the footer directly below the form, the "News has been successfully added to the database..." line will display below the footer which isn't how I need it to display.

    Before script executes (no footer):


    After:


    If I put the footer below the HTML form (other text moves past footer):


    I appreciate any help anyone can give.

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    looks like an html issue, not php.

    can you post the rendered html.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You force the script to die when you call if (!$_POST['submit']). That will not exist until the form is posted (and may not exist at all if you use IE; use if (isset($_POST['title'], $_POST['date'], $_POST['news'], $_POST['password'])) instead. $PHP_SELF is also a registered global which in this day and age shouldn't be relied on. Use $_SERVER['SCRIPT_NAME'] instead. Short tags is a feature that may not be enabled on all servers. You should use full <?php tags. Also, make sure to google up some php mysql injection as well, this is currently open for an injection.

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the new code:

    Code:
    if (isset($_POST['title'], $_POST['date'], $_POST['news'], $_POST['password']) != ("admin")){
    echo "You forgot to enter a title, date or news."; 
    die(); 
    
    }
    $addnews = mysql_query("INSERT INTO news VALUES ('NULL', '$_POST[title]', '$_POST[date]', '$_POST[news]')"); 
    echo "News has been successfully added to the database, it will now appear on the <a href='./index.php' class='Main'>homepage</a>.<br><br>"; 
    
    ?>
    <?php
    include "footer.php";
    include "analytics.php";
    ?>
    Now my password field doesn't work at all and my footer still does not display until after the script as executed.
    Last edited by RogueLayered; 04-20-2012 at 02:07 AM. Reason: Added stuff

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I'm not sure why you tried to change your check for the password. That certainly will not work as you are comparing a true/false value to a string.
    PHP Code:
    if (isset($_POST['title'], $_POST['date'], $_POST['news'], $_POST['password']) && $_POST['password'] == 'admin'))
    {
        
    // add news here.
    }
    else
    {
        print 
    'All fields are required';

    No die.


  •  

    Posting Permissions

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