BrianM Posted June 12, 2008 Share Posted June 12, 2008 <?php function report_create() { echo("<form action=\"".$_SERVER['PHP_SELF']."?table=".$_GET['table']."&project_name=".$_GET['project_name']."&report=create\" method=\"post\">"); echo("<b><font size=\"2px\" face=\"Verdana\">Create report: </font></b><input type=\"text\" name=\"report_\" /> <input type=\"submit\" name=\"report_create\" value=\"Create\" />"); echo("</form>"); } if (isset($_POST['report_create'])) { mysql_connect('localhost', 'brian', '') or die(mysql_error()); mysql_select_db('reports') or die(mysql_error()); mysql_query("INSERT INTO `$table` (date, report) VALUES ('".date("m-d-y")."', '".$_POST['report_']."')"); } ?> I want to be able to redirect to another page after that insert query is executed, but I can't use header() .. so is there any other way I can redirect after mysql_query is executed? Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/ Share on other sites More sharing options...
bluejay002 Posted June 12, 2008 Share Posted June 12, 2008 it would be better if you will use header though... if not, you can use Javascript instead to redirect to a different page: <?php echo "<script> window.location.href = '" . $url_to_redirect . "'; </script>"; exit; ?> Jay, Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/#findComment-563673 Share on other sites More sharing options...
BrianM Posted June 12, 2008 Author Share Posted June 12, 2008 Well I'm looking for an alternate because my script is telling me I've already sent header information so I can't use the header() function there. Will what you provided work as an alternative? Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/#findComment-563674 Share on other sites More sharing options...
sKunKbad Posted June 12, 2008 Share Posted June 12, 2008 You might check your query, in MySQL or phpMyAdmin, with the variables replaced to determine if the query syntax is perfect. If MySQL returns an error before the redirect, then that would cause the header() error you are experiencing because that error is output HTML. Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/#findComment-563675 Share on other sites More sharing options...
xtopolis Posted June 12, 2008 Share Posted June 12, 2008 Similarly you could use <?php echo '<meta http-equiv="refresh" content="0;url=http://www.someurl.com/" />'; exit(); ?> Look it up, 0 is the time it waits before performing the redirect. Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/#findComment-563697 Share on other sites More sharing options...
Vizor Posted June 12, 2008 Share Posted June 12, 2008 A common problem with header() saying that output has already started is that you have a space at the end of your PHP block, e.g. after ?> just highlight everything in a text editor and look for extra spaces as these count as output. Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/#findComment-563698 Share on other sites More sharing options...
bluejay002 Posted June 12, 2008 Share Posted June 12, 2008 Well I'm looking for an alternate because my script is telling me I've already sent header information so I can't use the header() function there. Will what you provided work as an alternative? well i did used it before... and it works! the idea of havin exit right away is so that the following code will not get executed, instead, the script will run right away. you might check out also the others' suggestions and see which suits you best. Link to comment https://forums.phpfreaks.com/topic/109842-header-already-sent-cant-redirect/#findComment-563701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.