andrew_biggart Posted February 18, 2010 Share Posted February 18, 2010 Hi there basically what I would like to do is when ever a user submits a thread on my forum instead of echo"your thread has been submitted" I would like for them to be redirected to the thread that they just submitted. I know that i need to do an sql statement to find out what the Post_id was but i have no idea where to start, can anyone give me any tips or point me in the right direction? Thanks This is the current submit thread file that I am using. <?php include("config.php"); if(isset($_POST['add_topic'])){ $Post_username=$_SESSION['myusername']; $Post_subject=$_POST['Post_subject']; $Post_message=$_POST['Post_message']; $Post_tags=$_POST['Post_tags']; $Post_type=$_POST['Post_type']; $Post_pp=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_forum_threadst (Post_username, Post_pp, Post_date, Post_subject, Post_message, Post_tags, Post_type)VALUES('$Post_username', '$Post_pp', NOW(), '$Post_subject', '$Post_message', '$Post_tags', '$Post_type')"; $result=mysql_query($sql); if($result){ echo "<h1 class=status_green>Your Post has been added successfully</h1>"; } // close connection mysql_close(); } else{ echo "<h1 class=status_red>Unfortunitly there has been a problem, Please try and resubmit your thread.</h1>"; }; ?> Quote Link to comment Share on other sites More sharing options...
schilly Posted February 18, 2010 Share Posted February 18, 2010 if($result){ $thread_id = mysql_insert_id(); header("Location: path_to_thead.php?id=$thread_id"); } something like that. Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted February 18, 2010 Author Share Posted February 18, 2010 Ok that has made me get my head around it alittle more but it still isnt working, problem one is that i get the error echo, and problem 2 is there is no redirect. This is what i changed it to. <?php include("config.php"); if(isset($_POST['add_topic'])){ $Post_username=$_SESSION['myusername']; $Post_subject=$_POST['Post_subject']; $Post_message=$_POST['Post_message']; $Post_tags=$_POST['Post_tags']; $Post_type=$_POST['Post_type']; $Post_pp=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_forum_threadst (Post_username, Post_pp, Post_date, Post_subject, Post_message, Post_tags, Post_type)VALUES('$Post_username', '$Post_pp', NOW(), '$Post_subject', '$Post_message', '$Post_tags', '$Post_type')"; $result=mysql_query($sql); if($result){ $Post_id = mysql_insert_id(); header("Location: forum_view.php?Post_id=$Post_id"); } // close connection mysql_close(); } else{ echo "<h1 class=status_red>Unfortunitly there has been a problem, Please try and resubmit your thread.</h1>"; }; ?> Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted February 18, 2010 Author Share Posted February 18, 2010 Ok I got rid of that problem with the error message being displayed, silly mistake on my behalf. Just cant get my head around what to do next?? <?php include("config.php"); if(isset($_POST['add_topic'])){ $Post_username=$_SESSION['myusername']; $Post_subject=$_POST['Post_subject']; $Post_message=$_POST['Post_message']; $Post_tags=$_POST['Post_tags']; $Post_type=$_POST['Post_type']; $Post_pp=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_forum_threadst (Post_username, Post_pp, Post_date, Post_subject, Post_message, Post_tags, Post_type)VALUES('$Post_username', '$Post_pp', NOW(), '$Post_subject', '$Post_message', '$Post_tags', '$Post_type')"; $result=mysql_query($sql); if($result){ $Post_id = mysql_insert_id(); header("Location: forum_view.php?Post_id=$Post_id"); } else{ echo "<h1 class=status_red>Unfortunitly there has been a problem, Please try and resubmit your thread.</h1>"; }; // close connection mysql_close(); } else{ } ?> Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted February 18, 2010 Author Share Posted February 18, 2010 Ok i have did abit of error checking and i can echo the result as a link which works, so the problem is with the redirecting... This is the whole page is there anything that would conflict with the redirection? <?php session_start(); if(isset($_SESSION['myusername'])) { } else{ header("location:register.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <!-- #BeginTemplate "default.dwt" --> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <!-- #BeginEditable "doctitle" --> <title>Home | Sign In | Register | Cont</title> <!-- #EndEditable --> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <link href="../css/layout.css" rel="stylesheet" type="text/css" /> <link href="../css/styles.css" rel="stylesheet" type="text/css" /> <link href="../css/content.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../js/jquery-latest.js"></script> <script type="text/javascript" src="../js/scrolltopcontrol.js"></script> <script type="text/javascript" src="../js/dropdown_menu.js"></script> <style type="text/css"> .style1 { border-width: 0px; } a { color: #C2E115; } </style> </head> <body> <div id="wrapper"> <a name="top_page" id="top_page"></a> <div id="masthead"> <form method="post"> <table class="masthead" cellpadding="0" cellspacing="0" style="width: 740px; height: 63px"> <tr> <td class="homelink" rowspan="2"> <a href="default.php"><img alt="iloveartonline | Homepage" height="63" src="../images/homelink_bg.png" width="450" class="style1" /></a> </td> <td class="subnav"> <?php if(isset($_SESSION['myusername'])) { echo " <a href='default.php'>Home</a> | <a href='my_account.php'>Account</a> | <a href='basket.php'>Shopping Cart</a> | <a href='logout.php'>Logout</a> "; } else{ echo " Welcome Guest, You are not Logged in. Please <a href='register.php'>Login</a> or <a href='register.php'>Register</a>. "; } ?> </td> </tr> <tr> <td class="searchbox"> <table> <tr> <td> <input class="search"name="search" type="text" value="Search our site" /></td> <td><a href="search_site.php"> <img alt="" class="style1" height="20" src="../images/searchbutton_bg.png" width="20" /></a></td> </tr> </table> </td> </tr> </table> </form> </div> <div id="top_nav_div"> <ul class="topnav"> <li> <a href="#">Artists</a> <ul class="subnav"> <li class="top"><a href="#">Search Artists</a></li> <li class="top"><a href="#">A - E</a></li> <li class="top"><a href="#">F - J</a></li> <li class="top"><a href="#">K - O</a></li> <li class="top"><a href="#">P - T</a></li> <li class="bottom"><a href="#">U - Y</a></li> </ul> </li> <li> <a href="#">Galleries</a> <ul class="subnav"> <li class="top"><a href="#">Search Images</a></li> <li class="top"><a href="#">A - E</a></li> <li class="top"><a href="#">F - J</a></li> <li class="top"><a href="#">K - O</a></li> <li class="top"><a href="#">P - T</a></li> <li class="bottom"><a href="#">U - Y</a></li> </ul> </li> <li> <a href="#">Art News</a> <ul class="subnav"> <li class="top"><a href="#">Search News</a></li> <li class="top"><a href="#">Latest News</a></li> <li class="bottom"><a href="#">Most Popular</a></li> </ul> </li> <li> <a href="forum_latest.php">Forum</a> <ul class="subnav"> <li class="top"><a href="#">Search Forum</a></li> <li class="top"><a href="forum_latest.php">View Forum</a></li> <li class="top"><a href="forum_add.php">Add a Topic</a></li> <li class="bottom"><a href="forum_mypost.php">My Topics</a></li> </ul> </li> <li> <a href="#">Shop</a> <ul class="subnav"> <li class="top"><a href="#">Search Shop</a></li> <li class="top"><a href="#">Visit Shop</a></li> <li class="top"><a href="#">Sell Art</a></li> <li class="bottom"><a href="#">View Art</a></li> </ul> </li> <li> <a href="#">Contests</a> <ul class="subnav"> <li class="bottom"><a href="#">Coming Soon</a></li> </ul> </li> <li> <a href="my_account.php">Account</a> <?php $username=$_SESSION['myusername']; if(isset($_SESSION['myusername'])) { echo " <ul class='subnav'> <li class='top'><a href='profile.php?username=$username'>View Profile</a></li> <li class='top'><a href='my_alerts.php'>View Alerts</a></li> <li class='top'><a href='my_messages.php'>View messages</a></li> <li class='top'><a href='view_blog.php'>View Blog</a></li> <li class='top'><a href='my_portfolio'>View Pieces</a></li> <li class='bottom'><a href='logout.php'>Logout</a></li> </ul> "; } else{ echo " <ul class='subnav'> <li class='bottom'><a href='register.php'>Login or Register</a></li> </ul> "; } ?> </li> <li> <a href="#">Upload</a> <ul class="subnav"> <li class="top"><a href="#">Upload Art</a></li> <li class="top"><a href="#">Upload Article</a></li> <li class="bottom"><a href="#">Upload Link</a></li> </ul> </li> <li> <a href="#">Contact</a> </li> </ul> </div> <!-- #BeginEditable "body" --> <div id="container"> <div id="left_col"> <br /> <table class="forum_left_col"> <tr> <td class="forum_admin"><a href="forum_admin.php" class="forum_admin">AdMiN's Thread's</a></td> </tr> <?php include("config.php"); require("functions.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst WHERE Post_username='AdMiN' ORDER BY Post_id DESC LIMIT 10 " ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <tr> <td class="forum_submenu"> <a href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>" class="forum_subs"><? short_description($rows['Post_subject']); ?></a> </td> </tr> <? // close while loop } // close connection mysql_close(); ?> </table> <br /> <table class="forum_left_col"> <tr> <td class="forum_latest"><a href="forum_latest.php" class="forum_latest">Latest Thread's</a></td> </tr> <?php include("config.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst ORDER BY Post_id DESC LIMIT 10" ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <tr> <td class="forum_submenu"> <a href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>" class="forum_subs"><? short_description($rows['Post_subject']); ?></a> </td> </tr> <? // close while loop } // close connection mysql_close(); ?> </table> <br /> <table class="forum_left_col"> <tr> <td class="forum_popular"><a href="forum_popular.php" class="forum_mostpopular">Popular Thread's</a></td> </tr> <?php include("config.php"); // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst ORDER BY Post_id DESC LIMIT 10" ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <tr> <td class="forum_submenu"> <a href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>" class="forum_subs"><? short_description($rows['Post_subject']); ?></a> </td> </tr> <? // close while loop } // close connection mysql_close(); ?> </table> <br /> <table class="forum_left_col"> <tr> <td class="forum_my"><a href="forum_mypost.php" class="forum_myposts">My Thread's</a></td> </tr> <?php include("config.php"); $username=$_SESSION['myusername']; // Retrieve data from database $sql="SELECT * FROM biggartfp9_forum_threadst WHERE Post_username='$username' ORDER BY Post_id DESC LIMIT 10 " ; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <tr> <td class="forum_submenu"> <a href="forum_view.php?Post_id=<? echo $rows['Post_id']; ?>" class="forum_subs"><? short_description($rows['Post_subject']); ?></a> </td> </tr> <? // close while loop } // close connection mysql_close(); ?> </table> <br /> <table class="forum_left_col"> <tr> <td class="forum_add"><a href="forum_add.php" class="forum_add">Add a Thread</a></td> </tr> <tr> <td> <a href="forum_add.php"> <img class="forum_add_post" alt="" height="94" src="../images/tell_your_stories.png" width="150"/></a></td> </tr> </table> <br /> </div> <div id="page_content"> <br /> <form method="post" action="#"> <table cellpadding="0" cellspacing="0" class="acc_status_table"> <tr> <td class="forum_ad">Add a Topic</td> </tr> <tr> <td class="acc_status_feed"> <?php include("config.php"); if(isset($_POST['add_topic'])){ $Post_username=$_SESSION['myusername']; $Post_subject=$_POST['Post_subject']; $Post_message=$_POST['Post_message']; $Post_tags=$_POST['Post_tags']; $Post_type=$_POST['Post_type']; $Post_pp=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_forum_threadst (Post_username, Post_pp, Post_date, Post_subject, Post_message, Post_tags, Post_type)VALUES('$Post_username', '$Post_pp', NOW(), '$Post_subject', '$Post_message', '$Post_tags', '$Post_type')"; $result=mysql_query($sql); if($result){ $Post_id = mysql_insert_id(); header("location:forum_view.php?Post_id=$Post_id"); } else{ echo "<h1 class=status_red>Unfortunitly there has been a problem, Please try and resubmit your thread.</h1>"; }; // close connection mysql_close(); } else{ } ?> <table> <tr> <td> <table cellpadding="0" cellspacing="0"> <tr> <td rowspan="2" class="forum_view_cat" style="width: 50px" valign="top"></td> <td class="forum_add_top"> <table style="width: 100%"> <tr> <td class="forum_add_h">Topic</td> <td class="forum_add_max">Max 50 Characters</td> </tr> <tr> <td colspan="2" class="forum_add_inputs"><input class="forum_add_input" name="Post_subject" type="text"/></td> </tr> </table> </td> <td rowspan="2" class="forum_view_pic" style="width: 65px" valign="top"></td> </tr> <tr> <td class="forum_add_bot"> <table style="width: 100%"> <tr> <td class="forum_add_h">Message</td> <td class="forum_add_max">Max 2000 Characters</td> </tr> <tr> <td colspan="2" class="forum_add_inputs"><textarea class="forum_add_text" cols="20" name="Post_message" rows="2"></textarea></td> </tr> <tr> <td class="forum_add_h">Tags</td> <td class="forum_add_max">Max 200 Characters</td> </tr> <tr> <td colspan="2" class="forum_add_inputs"><input class="forum_add_input" name="Post_tags" type="text"/></td> </tr> <tr> <td colspan="2" class="forum_add_key">Separate keywords with a comma</td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <table> <tr> <td><select name="Post_type" style="width: 117px"> <option>ILoveArt</option> </select> <input name="add_topic" type="submit" value="submit"/></td> </tr> </table> </form> <br /> </div> </div> <!-- #EndEditable --> <div id="footer"> <div id="footer_nav"> <table> <tr> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_a">Artists</td> </tr> <tr> <td class="f_subnav">Search Artists</td> </tr> <tr> <td class="f_subnav">A - E</td> </tr> <tr> <td class="f_subnav">F - J</td> </tr> <tr> <td class="f_subnav">K - O</td> </tr> <tr> <td class="f_subnav">P - T</td> </tr> <tr> <td class="f_subnav">U - Y</td> </tr> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_g">Galleries</td> </tr> <tr> <td class="f_subnav">Search Images</td> </tr> <tr> <td class="f_subnav">A - E</td> </tr> <tr> <td class="f_subnav">F - J</td> </tr> <tr> <td class="f_subnav">K - O</td> </tr> <tr> <td class="f_subnav">P - T</td> </tr> <tr> <td class="f_subnav">U - Y</td> </tr> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_an">Art News</td> </tr> <tr> <td class="f_subnav">Search News</td> </tr> <tr> <td class="f_subnav">Latest News</td> </tr> <tr> <td class="f_subnav">Most Popular</td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_f">Forum</td> </tr> <tr> <td class="f_subnav">Search Forum</td> </tr> <tr> <td class="f_subnav">View Forum</td> </tr> <tr> <td class="f_subnav">Add a Topic</td> </tr> <tr> <td class="f_subnav">My Topics</td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_s">Shop</td> </tr> <tr> <td class="f_subnav">Search Shop</td> </tr> <tr> <td class="f_subnav">View Shop</td> </tr> <tr> <td class="f_subnav">View Art</td> </tr> <tr> <td class="f_subnav">Sell Art</td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_c">Contests</td> </tr> <tr> <td class="f_subnav">Coming Soon</td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_ac">Account</td> </tr> <?php $username=$_SESSION['myusername']; if(isset($_SESSION['myusername'])) { echo " <tr> <td class='f_subnav'>View Profile</td> </tr> <tr> <td class='f_subnav'>View Alerts</td> </tr> <tr> <td class='f_subnav'>View Messages</td> </tr> <tr> <td class='f_subnav'>View Blog</td> </tr> <tr> <td class='f_subnav'>View Pieces</td> </tr> <tr> <td class='f_subnav'>Logout</td> </tr> "; } else{ echo " <tr> <td class='f_subnav'>Register</td> </tr> "; } ?> </table> </td> <td class="f_nav" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_u">Upload</td> </tr> <tr> <td class="f_subnav">Upload Art</td> </tr> <tr> <td class="f_subnav">Upload Article</td> </tr> <tr> <td class="f_subnav">Upload Link</td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> </table> </td> <td class="f_nav_e" style="width: 86px; height: 200px" valign="top"> <table> <tr> <td class="f_header_co">Contact</td> </tr> <tr> <td class="f_subnav">Contact Us</td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> <tr> <td class="f_subnav_e"></td> </tr> </table> </td> </tr> </table> </div> </div> </div> </body> <!-- #EndTemplate --> </html> Quote Link to comment Share on other sites More sharing options...
ldb358 Posted February 18, 2010 Share Posted February 18, 2010 a header cant be sent after any content has been printed add: ob_start(); what this does is it keeps the page from outputting content so add: ob_end_flush(); at the end of your page to display the contents of the page as normal(assuming there hasn't been a redirect) Quote Link to comment Share on other sites More sharing options...
schilly Posted February 18, 2010 Share Posted February 18, 2010 yes you can't have echo'd any code to the browser when you do a redirect. This includes any debug stuff you are printing to the screen. also add a exit(); after the redirect. Quote Link to comment 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.