jimmi8 Posted December 16, 2006 Share Posted December 16, 2006 HI,i have this code:PHP Code:<?php include ('header.inc'); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p><b>title</b> <input type="text" name="title" size="10" maxlength="20" value="" /></p> <p><b>body</b><textarea name="body" rows="10" columns="50"></textarea></p> <p>category</p><select name="category"> <option value="fish">fiah</option> <option value="fish"></option> </select> <div align="center"><input type="submit" name="submit" value="submit" /></div> <?php if(isset($_POST['submit'])) { if(isset($_POST['title'])) { $title = ($_POST['title']); } else { $title = NULL; } if(isset($_POST['body'])) { $body = ($_POST['body']); } else { $body = NULL; } if(isset($_POST['category'])) { $category = ($_POST['category']); } else { $category = NULL; } if ($title && $body && $category) { require_once ('mysql_connect.php'); $query = "INSERT INTO entries (blog_id, title, date_submitted, category, body) VALUES (NULL, '$title', NOW(), '$category', '$body')"; $result = mysql_query ($query); if($result) { echo '<p>entered please check the following</p>'; echo "$title', '$body', '$category"; exit(); } else { echo '<p>there was an error</p>'; } } else { echo '<p>there was an error</p>'; } } echo '</form>'; ?> <?php include ('footer.inc'); ?> I realise the code is probably a little antiquated ( im open to suggestions on how to improve it!) but it does do the job of validating my form and then inputting the data in to a database. Its my first script! Anyways the problem im having is that if you are successful the browser re-loads the page with the correct things echoed back but the footer include is missing, it doesnt display.could anyone tell me why? Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/ Share on other sites More sharing options...
jumpenjuhosaphat Posted December 16, 2006 Share Posted December 16, 2006 What is in the "header.inc" file? Could you submit that file too? Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/#findComment-142407 Share on other sites More sharing options...
jimmi8 Posted December 16, 2006 Author Share Posted December 16, 2006 HI,Yeah sure. heres the header code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title><?php echo $page_title; ?></title></head><body bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td width="100%" bgcolor="#666666"><font color="#CCCCCC"><big><b>Welcome to my site!</b></big></font></td> </tr> <tr> <td bgcolor="#CCCCCC"> <table width="100%" border="0" cellspacing="1" cellpadding="2"> <tr> <td align="center"><a href="index.php">Home</a></td> <td align="center"><a href="dateform.php">Date Form</a></td> <td align="center"><a href="calculator.php">Calculator</a></td> <td align="center"><a href="register.php">Register</a></td> </tr> </table></td> </tr></table><br /><!-- Script 3.2 header.inc ends here --><!-- PAGE SPECIFIC CONTENT STARTS HERE. -->and heres the footer:<!-- Script 3.3 footer.inc --><br /><table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#CCCCCC"> <tr> <td> <div align="center">© 2003 Larry E. Ullman and DMC Insights, Inc.</div></td> </tr></table></body></html>Please excuse the needless use of tables! I was following a tut that used this header and footer and just re-used them here! Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/#findComment-142420 Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 just out of curiosity... where does it redirect to? Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/#findComment-142423 Share on other sites More sharing options...
jumpenjuhosaphat Posted December 16, 2006 Share Posted December 16, 2006 Edit: Misinformed information Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/#findComment-142446 Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 lol... the <html><body> tags dont do anything on their own... try it[code]test<br><html>test<br><body>test<br></body>test<br></html>test<br>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/#findComment-142448 Share on other sites More sharing options...
Philip Posted December 16, 2006 Share Posted December 16, 2006 It is because you have exited the script, which is basically saying "stop here please!":[code]<?php if($result) { echo '<p>entered please check the following</p>'; echo "$title', '$body', '$category"; exit(); }?>[/code]So:[code] <?php include ('header.inc'); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>title <input type="text" name="title" size="10" maxlength="20" value="" /></p> <p>body<textarea name="body" rows="10" columns="50"></textarea></p> <p>category</p><select name="category"> <option value="fish">fiah</option> <option value="fish"></option> </select> <div align="center"><input type="submit" name="submit" value="submit" /></div> <?php if(isset($_POST['submit'])) { if(isset($_POST['title'])) { $title = ($_POST['title']); } else { $title = NULL; } if(isset($_POST['body'])) { $body = ($_POST['body']); } else { $body = NULL; } if(isset($_POST['category'])) { $category = ($_POST['category']); } else { $category = NULL; } if ($title && $body && $category) { require_once ('mysql_connect.php'); $query = "INSERT INTO entries (blog_id, title, date_submitted, category, body) VALUES (NULL, '$title', NOW(), '$category', '$body')"; $result = mysql_query ($query); if($result) { echo '<p>entered please check the following</p>'; echo "$title', '$body', '$category"; } else { echo '<p>there was an error</p>'; } } else { echo '<p>there was an error</p>'; } } echo '</form>'; include ('footer.inc');?>[/code]AHHH The code tags are all messing up![i]EDIT2: I would suggest renaming your title (has nothing to do with redirecting ;))[/i] Quote Link to comment https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/#findComment-142464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.