...

View Full Version : Footer not showing until php script executes



RogueLayered
04-12-2012, 03:21 AM
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:



<?
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("","","","","","","","","","","","","","","","","","","","","","");

//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):
http://roguelayeredtech.co.cc/img/2012-04-11_211339.png

After:
http://roguelayeredtech.co.cc/img/2012-04-11_211414.png

If I put the footer below the HTML form (other text moves past footer):
http://roguelayeredtech.co.cc/img/2012-04-11_211537.png

I appreciate any help anyone can give.

angst
04-12-2012, 05:42 AM
looks like an html issue, not php.

can you post the rendered html.

Fou-Lu
04-12-2012, 05:44 AM
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.

RogueLayered
04-20-2012, 01:48 AM
Here's the new 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.

Fou-Lu
04-20-2012, 04:49 AM
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.


if (isset($_POST['title'], $_POST['date'], $_POST['news'], $_POST['password']) && $_POST['password'] == 'admin'))
{
// add news here.
}
else
{
print 'All fields are required';
}

No die.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum