msaz87 Posted November 10, 2009 Share Posted November 10, 2009 Just wanted to know if it were possible to run an SQL process like updating or dumping a table and then have a header command redirect the page? Or if not... what else could be used to substitute an auto-redirect? Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/ Share on other sites More sharing options...
trq Posted November 10, 2009 Share Posted November 10, 2009 Of course its possible. Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954622 Share on other sites More sharing options...
Gayner Posted November 10, 2009 Share Posted November 10, 2009 Just wanted to know if it were possible to run an SQL process like updating or dumping a table and then have a header command redirect the page? Or if not... what else could be used to substitute an auto-redirect? Thanks for the help mysql_query("UPDATE ibf_members SET skin='{$_POST['skin']}' WHERE id={$ibforums->member['id']}"); header("Location: index.php?act=UserCP&CODE=MOD"); use something like that.. Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954624 Share on other sites More sharing options...
darkvengance Posted November 10, 2009 Share Posted November 10, 2009 Yes it is possible, just use the code Gayner gave you. Headers will work as long as there is no output displayed before them, so as long as there is not an error in your query then it should all go according to plan Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954635 Share on other sites More sharing options...
Gayner Posted November 10, 2009 Share Posted November 10, 2009 Yes, ignore all my stuff in my code just alter it to fit ur needs or put in whatever your query is. Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954636 Share on other sites More sharing options...
msaz87 Posted November 10, 2009 Author Share Posted November 10, 2009 Yes it is possible, just use the code Gayner gave you. Headers will work as long as there is no output displayed before them, so as long as there is not an error in your query then it should all go according to plan Just wanted to know if it were possible to run an SQL process like updating or dumping a table and then have a header command redirect the page? Or if not... what else could be used to substitute an auto-redirect? Thanks for the help mysql_query("UPDATE ibf_members SET skin='{$_POST['skin']}' WHERE id={$ibforums->member['id']}"); header("Location: index.php?act=UserCP&CODE=MOD"); use something like that.. I'm getting a header error, but the top of my code is pulling variables, a few if statements, then: <? include('../includes/db_connect.php'); ?> <? include('../includes/header.php'); ?> <?php $delete = $_REQUEST['delete']; $date_mo = $_REQUEST['league_date_mo']; $date_day = $_REQUEST['league_date_day']; $date_year = $_REQUEST['league_date_year']; if($date_mo <10) $date_mo = "0".$date_mo; if($date_day <10) $date_day = "0".$date_day; $league = $_REQUEST['league']; $date = $date_year."-".$date_mo."-".$date_day; $week = $_REQUEST['week']; $location = $_REQUEST['park']; $notes = $_REQUEST['notes']; ?> <?php if ($delete == "on") { ?> <?php foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Time: $better_gametime, Team: $team, Value: $value<br />"; // IF YOU NEED TO SEE THE OUTPUT, UNCOMMENT THIS mysql_query(" DELETE FROM schedules WHERE schedule_id = '$schedule_id'") or die(mysql_error()); header("Location: index.php"); } echo("The ".$date." schedule has been deleted."); ?> There's some echo junk beneath it that was a placeholder while I was looking for a redirect solution, but if, like you said, the header command is above it, it should work? Not sure what I'm doing wrong... thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954641 Share on other sites More sharing options...
darkvengance Posted November 10, 2009 Share Posted November 10, 2009 when using the header redirect method make sure you use the full address eg. http://www.mysite.com/index.php instead of index.php Also make absolutely sure that there is no output before you call the header. Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954646 Share on other sites More sharing options...
msaz87 Posted November 10, 2009 Author Share Posted November 10, 2009 I tried turning the URL into a full one and still no dice... the complete page code: <? include('../includes/db_connect.php'); ?> <? include('../includes/header.php'); ?> <?php $delete = $_REQUEST['delete']; $date_mo = $_REQUEST['league_date_mo']; $date_day = $_REQUEST['league_date_day']; $date_year = $_REQUEST['league_date_year']; if($date_mo <10) $date_mo = "0".$date_mo; if($date_day <10) $date_day = "0".$date_day; $league = $_REQUEST['league']; $date = $date_year."-".$date_mo."-".$date_day; $week = $_REQUEST['week']; $location = $_REQUEST['park']; $notes = $_REQUEST['notes']; ?> <?php if ($delete == "on") { ?> <?php foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Time: $better_gametime, Team: $team, Value: $value<br />"; mysql_query(" DELETE FROM schedules WHERE schedule_id = '$schedule_id'") or die(mysql_error()); } //echo("The ".$date." schedule has been deleted."); ?> <?php } else { foreach($_POST['deletetime'] as $time => $times) { list($delete_gametime,$t) = explode('|',$time); $dgt = strtotime($delete_gametime); $d_time = date("Hi",$dgt); //echo("Times: $times, Delete_GT: $d_time<br/>"); $gt_delete_query = " DELETE FROM schedules WHERE league_date = '$date' AND league = '$league' AND gametime = '$d_time'"; mysql_query($gt_delete_query) or die(mysql_error()); } foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Game Time: $better_gametime, Team: $value, A or B: $team<br />"; $time_strip = strtotime($better_gametime); $time_final = date("Hi",$time_strip); mysql_query(" UPDATE schedules SET league_date = '$date', league = '$league', park_id = '$location', week = '$week', notes = '$notes', field = '$fld', gametime = '$time_final', team = '$value', a_or_b = '$team' WHERE schedule_id = '$schedule_id'") or die(mysql_error()); header("Location: http://[url]/index.php"); } ?> <?php echo("The ".$date." schedule has been edited."); ?> <form action="../edit_schedule.php"> <input type="submit" value="return to previous page"> </form> <?php } ?> I've looked a few times and don't see any output beforehand... am I blind? Thanks for the help... Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954655 Share on other sites More sharing options...
Gayner Posted November 10, 2009 Share Posted November 10, 2009 Delete all the spaces between <?php ?> <?php ?> tags lol Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954657 Share on other sites More sharing options...
darkvengance Posted November 10, 2009 Share Posted November 10, 2009 I'm not sure what the problem is...have you check the db_connect.php header.php files to make sure there is no output in them...oh also make sure there are no spaces before the opening tags in both this document and the two you are including whoops...nevermind I see it now... <? include('../includes/db_connect.php'); ?> <? include('../includes/header.php'); ?> <?php All of those blank spaces count as output...here try this: <?php include('../includes/db_connect.php'); include('../includes/header.php'); $delete = $_REQUEST['delete']; $date_mo = $_REQUEST['league_date_mo']; $date_day = $_REQUEST['league_date_day']; $date_year = $_REQUEST['league_date_year']; if($date_mo <10) $date_mo = "0".$date_mo; if($date_day <10) $date_day = "0".$date_day; $league = $_REQUEST['league']; $date = $date_year."-".$date_mo."-".$date_day; $week = $_REQUEST['week']; $location = $_REQUEST['park']; $notes = $_REQUEST['notes']; if ($delete == "on") { foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Time: $better_gametime, Team: $team, Value: $value<br />"; mysql_query("DELETE FROM schedules WHERE schedule_id = '$schedule_id'") or die(mysql_error()); } //echo("The ".$date." schedule has been deleted."); } else { foreach($_POST['deletetime'] as $time => $times) { list($delete_gametime,$t) = explode('|',$time); $dgt = strtotime($delete_gametime); $d_time = date("Hi",$dgt); //echo("Times: $times, Delete_GT: $d_time<br/>"); $gt_delete_query = "DELETE FROM schedules WHERE league_date = '$date' AND league = '$league' AND gametime = '$d_time'"; mysql_query($gt_delete_query) or die(mysql_error()); } foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Game Time: $better_gametime, Team: $value, A or B: $team<br />"; $time_strip = strtotime($better_gametime); $time_final = date("Hi",$time_strip); mysql_query(" UPDATE schedules SET league_date = '$date', league = '$league', park_id = '$location', week = '$week', notes = '$notes', field = '$fld', gametime = '$time_final', team = '$value', a_or_b = '$team' WHERE schedule_id = '$schedule_id'") or die(mysql_error()); header("Location: http://[url]/index.php"); } echo("The ".$date." schedule has been edited."); ?> <form action="../edit_schedule.php"> <input type="submit" value="return to previous page"> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954659 Share on other sites More sharing options...
dreamwest Posted November 10, 2009 Share Posted November 10, 2009 You have to check if headers have been sent yet: function redirect( $url ){ if (! headers_sent( ) ){ header( "Location: ".$url ); exit( 0 ); } echo "<script language=Javascript>document.location.href='".$url."';</script>"; exit( 0 ); } redirect('any url here you want'); Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954664 Share on other sites More sharing options...
msaz87 Posted November 10, 2009 Author Share Posted November 10, 2009 I went back and got rid of the includes, and all the spaces... and still errors... <?php $db_server = "XXX"; $db_user = "XXX"; $db_pass = "XXX"; $db_name = "XXX"; $schedule_db = mysql_connect($db_server, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error()); //include('../includes/db_connect.php'); //include('../includes/header.php'); $delete = $_REQUEST['delete']; $date_mo = $_REQUEST['league_date_mo']; $date_day = $_REQUEST['league_date_day']; $date_year = $_REQUEST['league_date_year']; if($date_mo <10) $date_mo = "0".$date_mo; if($date_day <10) $date_day = "0".$date_day; $league = $_REQUEST['league']; $date = $date_year."-".$date_mo."-".$date_day; $week = $_REQUEST['week']; $location = $_REQUEST['park']; $notes = $_REQUEST['notes']; if ($delete == "on") { foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Time: $better_gametime, Team: $team, Value: $value<br />"; // IF YOU NEED TO SEE THE OUTPUT, UNCOMMENT THIS mysql_query(" DELETE FROM schedules WHERE schedule_id = '$schedule_id'") or die(mysql_error()); } //echo("The ".$date." schedule has been deleted."); } else { foreach($_POST['deletetime'] as $time => $times) { list($delete_gametime,$t) = explode('|',$time); $dgt = strtotime($delete_gametime); $d_time = date("Hi",$dgt); //echo("Times: $times, Delete_GT: $d_time<br/>"); $gt_delete_query = " DELETE FROM schedules WHERE league_date = '$date' AND league = '$league' AND gametime = '$d_time'"; mysql_query($gt_delete_query) or die(mysql_error()); } foreach($_POST['slot'] as $key => $value){ list($schedule_id,$fld,$better_gametime,$team) = explode('|',$key); //echo "Schedule ID: $schedule_id, Field: $fld, Game Time: $better_gametime, Team: $value, A or B: $team<br />"; // IF YOU NEED TO SEE THE OUTPUT, UNCOMMENT THIS $time_strip = strtotime($better_gametime); $time_final = date("Hi",$time_strip); mysql_query(" UPDATE schedules SET league_date = '$date', league = '$league', park_id = '$location', week = '$week', notes = '$notes', field = '$fld', gametime = '$time_final', team = '$value', a_or_b = '$team' WHERE schedule_id = '$schedule_id'") or die(mysql_error()); header("Location: http://[url]/index.php"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954667 Share on other sites More sharing options...
darkvengance Posted November 10, 2009 Share Posted November 10, 2009 Hmm... just try doing what dreamwest said...replace the header with this: if (!headers_sent()){ header("Location: http://[url]/index.php"); exit(); }else{ echo "<script language='Javascript'>document.location.href='http://[url]/index.php';</script>"; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954670 Share on other sites More sharing options...
msaz87 Posted November 10, 2009 Author Share Posted November 10, 2009 That works... just weird why the header method won't work... Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954675 Share on other sites More sharing options...
darkvengance Posted November 10, 2009 Share Posted November 10, 2009 No problem man, good luck with everything else Quote Link to comment https://forums.phpfreaks.com/topic/180948-solved-redirect-following-sql-action/#findComment-954680 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.