wright67uk Posted February 17, 2013 Share Posted February 17, 2013 I have a form which posts to ranges_process.php (shown below) I have an error; Warning: Cannot modify header information - headers already sent by (output started at urlhere/ranges_process.php:3) in sameurlhere/ranges_process.php on line 37 Ive checked and as far as I can see, im not echoing or printing anything. What could be causing this warning? <?php session_start();?> <?php $user_id = $_SESSION['user_id']; if(isset($_POST['processForm'])) { $yards = $_POST['yards']; $club = $_POST['club']; $date = $_POST['date']; $competition = $_POST['location']; if (empty($date)) {$a= "<br />You haven't entered a date"; $errors_found = true;} if (!is_numeric($yards)) {$b= "<br />You haven't entered a distance!"; $errors_found = true;} if (empty($club)) {$c= "<br/>You haven't selected a club!"; $errors_found = true;} if (empty($competition)) {$d= "<br />You haven't entered a location"; $errors_found = true;} if (!$errors_found) { $date = str_replace("-","",$date); $year =substr($date,0,4); //CONNECTION HERE $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "INSERT INTO TABLENAMEHERE (user_id, yard, club, date, year, competition) VALUES ('$user_id', '$yards', '$club', '$date', '$year', '$competition')"; mysql_query($sql); $e= '<br/><br/>A distance, has now been added.'; }}; header("Location: http://URLHERE/beta/ranges2.php?a=$a&b=$b&c=$c&d=$d&e=$e"); // line 37 //RETURN TO ORIGINAL LOCATION... ?> Quote Link to comment https://forums.phpfreaks.com/topic/274588-my-header-refresh-is-not-working/ Share on other sites More sharing options...
wright67uk Posted February 17, 2013 Author Share Posted February 17, 2013 header("Location:ranges2.php?a=$a&b=$b&c=$c&d=$d&e=$e"); I have no idea why but when I changed my URL, everything worked fine... Quote Link to comment https://forums.phpfreaks.com/topic/274588-my-header-refresh-is-not-working/#findComment-1412910 Share on other sites More sharing options...
DavidAM Posted February 17, 2013 Share Posted February 17, 2013 This tells you exactly where you started sending output -- The :3 here means LINE 3 of that file. output started at urlhere/ranges_process.php:3 If this is your actual code, then this is your problem <?php session_start();?> <?php $user_id = $_SESSION['user_id']; Everything outside of PHP tags -- including those two blank lines -- is sent to the browser as content. There is no reason to break out of and back into PHP here. I have no idea why but when I changed my URL, everything worked fine... If should NOT make any difference to that particular error. And FYI, the specs say that the URL in the Location header must be absolute (so you had it right the first time). Quote Link to comment https://forums.phpfreaks.com/topic/274588-my-header-refresh-is-not-working/#findComment-1412937 Share on other sites More sharing options...
bleured27 Posted February 17, 2013 Share Posted February 17, 2013 <?php session_start();?> <?php $user_id = $_SESSION['user_id']; if(isset($_POST['processForm'])) { $yards = $_POST['yards']; $club = $_POST['club']; $date = $_POST['date']; $competition = $_POST['location']; if (empty($date)) {$a= "<br />You haven't entered a date"; $errors_found = true;} if (!is_numeric($yards)) {$b= "<br />You haven't entered a distance!"; $errors_found = true;} if (empty($club)) {$c= "<br/>You haven't selected a club!"; $errors_found = true;} if (empty($competition)) {$d= "<br />You haven't entered a location"; $errors_found = true;} CTRL + Q to Enable/Disable GoPhoto.it besides that you need to do something about the lay out it is not handy for other pprogrammers including yourself to read messy code first of all you can do this <?php if($x!=$y): echo"x is not y";endif; ?> and this <?php if($x!=$y) TAB{ TABTAB echo"x is not y"; TABTAB if($x>$Y) TABTAB { TABTABTAB echo"x is more than y" TABTAB } TABTAB else TABTAB { TABTABTAB echo"y is probebly equal or bigger than x"; TABTAB } TAB} ?> Quote Link to comment https://forums.phpfreaks.com/topic/274588-my-header-refresh-is-not-working/#findComment-1412940 Share on other sites More sharing options...
wright67uk Posted February 18, 2013 Author Share Posted February 18, 2013 Thanks David! bleured27 what TABTABTAB is all this CTRL AND Q all about? Quote Link to comment https://forums.phpfreaks.com/topic/274588-my-header-refresh-is-not-working/#findComment-1413069 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.