PHP - I Have A Form That Is Sending Back A "cannot Modify Header Information"
Cannot modify header information - headers already sent by (output started at ) on line 179
I labeled 179 its at the bottom. I understand this means its already generating the html but not how or where. A solution would of course be nice but if some one could tell me even how to figure it out it would be great. Code: [Select] <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "test@test.com"; $email_subject = "$mile"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } /*"trail_section_mile", float dash "trail_section_name", #9()alphanumeric "name", "date"auto date "email",same "telephone" same "trail_condition" no validation just sanitize size limit "attention_area" no validation just sanitize size limit "under_20" no validation just sanitize size limit "_20_54" no validation just sanitize size limit "_55_over" no validation just sanitize size limit */ if(!isset($_POST['trail_section_mile']) ) { died('1'); } if(!isset($_POST['trail_section_name']) ) { died('2'); } if(!isset($_POST['name']) ) { died('3'); } if(!isset($_POST['email']) ) { died('4'); } if(!isset($_POST['telephone']) ) { died('5'); } if(!isset($_POST['trail_condition']) ) { died('6'); } if(!isset($_POST['attention_area']) ) { died('7'); } if(!isset($_POST['under_20']) ) { died('8'); } if(!isset($_POST['_20_54']) ) { died('9'); } if(!isset($_POST['_55_over']) ) { died('0'); } if(!isset($_POST['total_hours']) ) { died('011'); } //comments field is a honeypot require ('Validate.php'); $email = $_REQUEST['email']; $validate = new Validate(); if (!Validate::email($email, array('check_domain' => true, 'use_rfc822' =>true))) { echo "Invalid email"; } $trail_section_mile = $_POST['trail_section_mile']; // required $trail_section_name = $_POST['trail_section_name']; // required $name = $_POST['name']; // required $email = $_POST['email']; // required $telephone = $_POST['telephone']; // required $trail_condition = $_POST['trail_condition']; // required $attention_area = $_POST['attention_area']; // required $under_20 = $_POST['under_20']; $_20_54 = $_POST['_20_54']; $_55_over = $_POST['_55_over']; $_55_over = $_POST['total_hours']; // required if (preg_match('/[\d\D\b\B\s\S]/', $comments)) { echo "nope"; } if (!preg_match("/([\w\.\#\-\,]{1,30})+/", $trail_section_mile)) {echo "please enter the section mile markers again only numbers, decimals dashes and # are aloud"; } if (!preg_match("/[a-z'-]+/", $trail_section_name)) { echo "Try your last name again."; } if (!preg_match("/[a-z'-]+/", $name)) { echo "please re-type your address."; } if (!preg_match("/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/i", $telephone)) { echo "Something is wrong with the phone number you intered. Please enter your area code first then ther rest of tyour number."; } if (( preg_match( "/[\r\n]/", $first_name ) || preg_match( "/[\r\n]/", $email ) || preg_match( "/[\r\n]/", $last_name) ) || preg_match( "/[\r\n]/", $state)) { echo "nope"; } $trail_section_mile = strip_tags($trail_section_mile); $trail_section_name = strip_tags($trail_section_name); $name =strip_tags($name); $email = strip_tags($email); $telephone = strip_tags($telephone); $trail_condition = strip_tags($trail_condition); $attention_area = strip_tags($attention_area); $under_20 = strip_tags($under_20); $_20_54 = strip_tags($_20_54); $_55_over = strip_tags($_55_over); $total_hours = strip_tags($total_hours); $trail_section_mile = htmlspecialchars($trail_section_mile); $trail_section_name = htmlspecialchars($trail_section_name); $name = htmlspecialchars($name); $email = htmlspecialchars($email); $telephone = htmlspecialchars($telephone); $trail_condition = htmlspecialchars($trail_condition); $attention_area = htmlspecialchars($attention_area); $under_20 = htmlspecialchars($under_20); $under_20 = htmlspecialchars($_20_54); $_55_over = htmlspecialchars($_55_over); $total_hours = htmlspecialchars($total_hours); $email_message = "Form details below.\n\n"; $email_message = date("m/d/Y") . "\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Trail Section Mile Markers: ".clean_string($trail_section_mile)."\n"; $email_message .= "Trail Section Name : ".clean_string($trail_section_name)."\n"; $email_message .= "Reported by: ".clean_string($name)."\n"; $email_message .= "Email Address: ".clean_string($email)."\n"; $email_message .= "Telephone Number: ".clean_string($telephone)."\n"; $email_message .= "General Trail Condition : ".clean_string($trail_condition)."\n"; $email_message .= "Mile #/Problem/Suggested Improvements: ".clean_string($attention_area)."\n"; $email_message .= "Volunteers Under Age 20 #Males/#Females/Ethnicity/Name: ".clean_string($under_20)."\n"; $email_message .= " Volunteers Ages 20 to 54 #Males/#Females/Ethnicity/Name: ".clean_string($_20_54)."\n"; $email_message .= "Volunteers Age 55+ #Males/#Females/Ethnicity/Name: ".clean_string($_55_over)."\n"; $email_message .= "Total Volunteer Hours: ".clean_string($total_hours)."\n"; $about ="Maintenance Report from" .$name. "/n"; // create email headers $headers = 'Subject : '.$about."/r/n" .'From: '.$email."\r\n" .'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); header("Location: oht/maintenance/maintenance-report/thank-you/"); //line 179 @mail($email_to, $email_subject, $email_message, $headers); ?> <?php } ?> MOD EDIT: [code] . . . [/code] BBCode tags added. Similar TutorialsI have a registration form on my website and after Registration I want the user to activate first his account. I don't have problem on sending this email to the user. What I want to appear is like this.. GoodDay "username", Blah Blah! how can you actually do that? I know that you can do that through session variables but the thing is email's can't accept scripts on sending emails. how can I get the value from a session variable for example and convert it to plain html text so that i can OUTPUT it to the email.. HELP PLEASE! As my titel indicates, I have a problem with a piece of code I wrote some time ago. Everything in my mail form is fine and the mails do get send. But they don't always arrive (checked spam folder). Hotmail or example arrives but a normal email adres from a provider does not. Could this have something to do with SMTP ? could I add this to my code ? I tryed some but so far it does not work, In the code below you can see my working code as it is & the tests I tryed and didn't work out that well. Code: [Select] <?php $fromemail="No-Reply <ikwerkthuis.be>"; // change here if you want $toemail=$naarwie; // change here if you want $sub="Online info aanvraag"; // change here if you want $success_page_name="bedankt.html"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3'])); $fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4'])); $fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5'])); $fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6'])); $fieldnm_7=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_7'])); $contentmsg=stripslashes('<br><b><font style=color:#CC3300>'. $sub .'</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_1 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_2 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_3 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_4 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_5 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_6 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Regio *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_7 .'</td> </tr> </table><br> Contactpersoon: '. $naarwie .'<br> IP: '. $IP .'<br> Date: '. $DATE .'<br> Time: '. $TIME .' '); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; @mail($toemail,$sub,$contentmsg,$headers);?> The code below is the code I tryed to apply to the code above that work. Code: [Select] <?php $fromemail="No-Reply <noreply@ikwerkthuis.be>"; // change here if you want $toemail=$naarwie; // change here if you want $sub="Online info aanvraag"; // change here if you want $success_page_name="bedankt.html"; $host = "ikwerkthuis.be"; $username = "noreply@ikwerkthuis.be"; $password = "hl2012"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3'])); $fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4'])); $fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5'])); $fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6'])); $fieldnm_7=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_7'])); $contentmsg=stripslashes('<br><b><font style=color:#CC3300>'. $sub .'</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_1 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_2 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_3 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_4 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_5 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_6 .'</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Regio *:</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_7 .'</td> </tr> </table><br> Contactpersoon: '. $naarwie .'<br> IP: '. $IP .'<br> Date: '. $DATE .'<br> Time: '. $TIME .' '); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); @mail = $smtp->send($toemail,$sub,$contentmsg,$headers); ?> I hope someone can help me out. Thanks in advance ! Can someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Hey guys im getting the error Warning: Cannot modify header information - headers already sent by (output started at /home/kylegray/public_html/include/authenticate.php:12) in /home/kylegray/public_html/home.php on line 7 Any idea why this is coming up. I think its something to to with me setting the cookie setcookie("un", $id); but im not sure. home.php Code: [Select] <? include("include/config.php"); //$_SESSION["backpage"]=$_SERVER['PHP_SELF']; if($_SESSION["client_log"]!="true"){ session_unregister("MemberArea"); header("Location: index.php?redirect=".basename($_SERVER['PHP_SELF'])); exit(); } ?> authenticate.php Code: [Select] <?php include("include/required.php"); include("include/pagedetails.php"); include_once("include/authenticate.php"); $tblName = $tbluser; $id=$_SESSION["id"]; setcookie("un", $id); $ImgPath="$CatImage/"; $ImgPathsing="$SingUPImage/"; ?> i have problem when adding a subject it got two subject that need to be selected by teacher , management sub and DBMS sub.. said Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\PhpProject3\navhead_user.php:57) in C:\xampp\htdocs\PhpProject3\teacher_add_subject.php on line 104.. when i select one of them it appear that error.. but when i select DBMS it inserted the subject but with error.. let say 1st i selecting management as the subject, it occur error but after refresh the page it appear in the list of the teacher subject then i add another subject DBMS subject and it occur error but the management subject is dissappear from the teach subject list.. but i try to add the management subject again it said it existed but not listed.. but in my database it inside there already only the data not appear..
navhead_user.php
<div class="row-fluid"> <div class="span12"> <div class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <div class="container"> <!-- .btn-navbar is used as the toggle for collapsed navbar content --> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <!-- Be sure to leave the brand out there if you want it shown --> <!-- Everything you want hidden at 940px or less, place within here --> <div class="nav-collapse collapse"> <!-- .nav, .navbar-search, .navbar-form, etc --> <i class="icon-facebook-sign icon-large" id="color_white"></i> <i class="icon-twitter icon-large" id="color_white"></i> <i class="icon-google-plus icon-large" id="color_white"></i> <i class="icon-github-alt icon-large" id="color_white"></i> <i class="icon-linkedin-sign icon-large" id="color_white"></i> <div class="pull-right"> <form class="navbar-search pull-left"> <i class="icon-search icon-large" id="color_white"></i> <input type="text" class="search-query" placeholder="Search"> </form> </div> <!-- end collapse --> </div> </div> </div> </div> <div class="hero-unit-header"> <div class="container"> <div class="row-fluid"> <div class="span12"> <div class="row-fluid"> <div class="span6"> <img src="admin/images/head.png"> </div> <div class="span6"> <div class="pull-right"> <!--- login button --> <?php $student_query=mysql_query("select * from teacher where teacher_id='$session_id'")or die(mysql_error()); $teacher_row= mysql_fetch_array($student_query); ?> <img src="admin/<?php echo $teacher_row['location']; ?>" class="img img-rounded" id="picture"> <div class="btn-group"> <button class="btn btn-success"><i class="icon-user icon-large"></i> <?php echo $user_row['firstname'] . " " . $user_row['lastname']; ?></button> <button class="btn dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#logout" role="button" data-toggle="modal"><i class="icon-signout icon-large"></i> Logout</a></li> </ul> </div> <?php include('logout_modal.php') ?> </div> </div> </div> </div> </div> </div> </div>teacher_add_subject.php <?php include ('session.php'); ?> <?php include('header.php'); $user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <body> <?php include('navhead_user.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="teacher_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li> <a href="teacher_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i> Subjects <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li><a href="students.php"><i class="icon-group icon-large"></i> Students <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="teacher_subject.php" class="btn btn-success"><i class="icon-arrow-left icon-large"></i> Back</a> <br> <br> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Add Subject</strong> </div> <div class="hero-unit-2"> <form class="form-horizontal" method="POST"> <div class="control-group"> <label class="control-label" for="inputEmail">Subject</label> <div class="controls"> <select name="subject" class="span6"> <option></option> <?php $query = mysql_query("select * from subject") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { ?> <option value="<?php echo $row['subject_id']; ?>"><?php echo $row['subject_title']; ?></option> <?php } ?> </select> </div> </div> <div class="control-group"> <div class="controls"> <button type="submit" name="save_subject" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Add Subject</button> </div> <br> <?php if (isset($_POST['save_subject'])) { $subject = $_POST['subject']; $result = mysql_query("select * from teacher_suject where teacher_id='$session_id' and subject_id='$subject'") or die(mysql_error()); $count = mysql_num_rows($result); if ($count > 0) { ?> <div class="alert alert-danger">Subject <strong>Already Exist</strong></div> <?php } else { mysql_query("insert into teacher_suject (subject_id,teacher_id) values('$subject','$session_id')") or die(mysql_error()); header('location:teacher_subject.php'); } } ?> </div> </form> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html>teacher_subject.php <?php include ('session.php'); ?> <?php include('header.php'); $user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <body> <?php include('navhead_user.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="teacher_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li> <a href="teacher_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i> Subjects <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li><a href="students.php"><i class="icon-group icon-large"></i> Students <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="teacher_add_subject.php" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Add Subject</a> <br> <br> <div class="hero-unit-3"> <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Subject Table</strong> </div> <thead> <tr> <th>Course Code</th> <th>Course Description</th> <th>Action</th> </tr> </thead> <tbody> <?php $teacher_subject_query = mysql_query("select * from teacher_suject where teacher_id='$session_id'") or die(mysql_error()); $teacher_row = mysql_fetch_array($teacher_subject_query); $subject_id = $teacher_row['subject_id']; $query = mysql_query("select * from subject where subject_id = '$subject_id'") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $id = $row['subject_id']; ?> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#d<?php echo $subject_id; ?>').tooltip('show') $('#d<?php echo $subject_id; ?>').tooltip('hide') }); </script> <!-- end script --> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#e<?php echo $subject_id; ?>').tooltip('show') $('#e<?php echo $subject_id; ?>').tooltip('hide') }); </script> <!-- end script --> <tr class="odd gradeX"> <td><?php echo $row['subject_code']; ?></td> <td><?php echo $row['subject_title']; ?></td> <td width="50"> <a rel="tooltip" title="Delete Subject" id="d<?php echo $subject_id; ?>" href="#id<?php echo $id; ?>" role="button" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i> </a> </td> <!-- user delete modal --> <div id="id<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> </div> <div class="modal-body"> <div class="alert alert-danger">Are you Sure you Want to <strong>Delete</strong> this Subject?</div> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button> <a href="delete_teacher_course.php<?php echo '?id=' . $course_id; ?>" class="btn btn-danger"><i class="icon-trash icon-large"></i> Delete</a> </div> </div> <!-- end delete modal --> </tr> <?php } ?> </tbody> </table> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html> Edited by aquilina, 26 May 2014 - 04:43 PM. Hey guys, I've searched on Google for this and have had no luck, and you guys have been EXTREMELY helpful with a few of my previous questions! Alright the error I get is: Warning: Cannot modify header information - headers already sent by (output started at /****/header.php:6) in /***/*login.php on line 65 Errr.. After I posted this I saw the Sticky regarding Header posts.. I read the post and cannot find where the issue is with this.. The PHP code comes before the form information, am I missing something? My login.php script is: Code: [Select] <?php include("header.php"); mysql_connect("10.6.186.84", "gilmdiniz", "Gil19471947") or die(mysql_error()); mysql_select_db("gilmdiniz") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else echo "SUP";//header($hdir."files.php"); } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) die('<center>You did not fill in a required field! <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); if (!get_magic_quotes_gpc()) $_POST['email'] = addslashes($_POST['email']); $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) die('<center>This username does not exist in our database, sorry. <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) die('<center>Incorrect password, please try again. <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); echo "SUP";//header($hdir."files.php"); } } } else { ?> <center> <a href="<?php echo $hdir .'index.php'; ?>"> Back to Home </a> <table border="1"> <tr><td> <center><h2>Login Information</h2></center> </td></tr> <tr><td> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td> Username: </td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td> Password: </td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> </td></tr> </table> </center> <?php } ?> and my header.php script is: Code: [Select] <?php $hdir = "http://www.ondemandagents.com/NewSite_ALPHA/"; ?> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="<?php echo $hdir .'style.css'; ?>" /> </head> <body> <table width="920" cellspacing="0" cellpadding="10" border="0" align="center"> <tr> <td class="bodyline"> <table align="center" border="0" width="635" height="121" background="<?php echo $hdir .'images/logo.png'; ?>"> <tr> <td height="69"> <table border="0" width="635" height="106"> <tr> <td width="800" height="70"> </td> <td width="600" height="70"> </td> </tr> <tr> <td width="400" height="18"> </td> <td width="600" height="18"> <a href="<?php echo $hdir .'index.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_home.gif'; ?>" width="12" height="13" border="0" alt="Home" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Home </font></a> <a href="<?php echo $hdir .'files.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_files.gif'; ?>" width="12" height="13" border="0" alt="Files" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Files </font></a> <a href="<?php echo $hdir .'admin.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_login.gif'; ?>" width="12" height="13" border="0" alt="Administration" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Administration</font></a> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> I have been using a header file in all my pages and scripts so far so that I wouldn't have to keep typing repetitive code.. Help is MUCH appreciated! Thanks in advance guys i Have a php code... Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) { header('Location: login.php'); die (" "); } if($_GET['via']=="pre_pass") { $prepass=$_POST['currentpassword']; $newpass=$_POST['newpass']; $renewpass=$_POST['renewpass']; /*$answer=$_POST['answer']; &newpassword=$_POST['newpassword']; */ if($prepass!=NULL && $newpass!=NULL && $renewpass!=NULL ) { if(strlen($prepass)==0 || strlen($newpass)==0 || strlen($renewpass)==0) { session_start(); $_SESSION['status']="Please fill out all the fields"; header('location:change_password.php?via=previous_password'); die(" "); } if(strlen($prepass)<6 || strlen($newpass)<6 || strlen($renewpass)<6) { session_start(); $_SESSION['status']="All fields must have atleast 6 characters"; header('location:change_password.php?via=previous_password'); die(" "); } if(strcmp($newpass, $renewpass)!=0 && strlen($prepass)>=6 && strlen($newpass)>=6 && strlen($renewpass)>=6 ) { session_start(); $_SESSION['status']="New password does not match with each other"; header('location:change_password.php?via=previous_password'); die(" "); } if(strcmp($prepass, $newpass)==0) { session_start(); $_SESSION['status']="New password and Previous Password must be different"; header('location:change_password.php?via=previous_password'); die(" "); } mysql_connect ("localhost:3306", "feadmin1","lycosanmamba" ) or die ('Error connecting database'); mysql_select_db ("fe_user_info"); $reguserpassword = stripslashes($prepass); $reguserpassword = mysql_real_escape_string($reguserpassword); $newpass = stripslashes($newpass); $newpass = mysql_real_escape_string($newpass); $sql = "select * from user_info where id='$_SESSION[id]' and password='$reguserpassword'"; $res=mysql_query($sql); $count=mysql_num_rows($res); if($count=='1') { $query= "UPDATE user_info SET password='".$newpass."' WHERE id='$_SESSION[id]'"; mysql_query($query); session_start(); $_SESSION['status']="Password Successfully Changed"; $_SESSION['mail']="positive"; include("mail/pasword_change_verify_mail.php"); header('location:change_password.php?via=previous_password'); die(" "); } if($count!='1') { session_start(); $_SESSION['status']="Password you entered does not match with our records"; header('location:change_password.php?via=previous_password'); die(" "); } } } if($_GET['via']=="sec_ques") { $answer=$_POST['answer']; $newpassword=$_POST['newpassword']; if($answer!=NULL && $newpassword!=NULL) { include('db_connectivity.php'); $sql2 = "select * from user_info where id='$_SESSION[id]' and security_answer='$answer'"; $res2=mysql_query($sql2); $count2=mysql_num_rows($res2); if(strlen($newpassword)<6) { session_start(); $_SESSION['status']="Password must have atleast 6 characters"; header('location:change_password.php?via=security_question'); die(" "); } if($count2=='1') {include('db_connectivity.php'); $newpassword = stripslashes($newpassword); $newpassword = mysql_real_escape_string($newpassword); $query= "UPDATE user_info SET password='".$newpassword."' WHERE id='$_SESSION[id]'"; mysql_query($query); session_start(); $_SESSION['status']="Password Successfully Changed"; $_SESSION['mail']="positive"; include("mail/pasword_change_verify_mail.php"); header('location:change_password.php?via=security_question'); die(" "); } else { session_start(); $_SESSION['status']="Answer to this security question is incorrect"; header('location:change_password.php?via=security_question'); die(" "); } } } ?> but when i run this code it shows me the error.. Warning: Cannot modify header information - headers already sent by (output started at C:.................................:2) in C:\...............................\verify_change_password.php on line 118 CODE BETWEEN LINE 110-120 is Code: [Select] $newpassword = mysql_real_escape_string($newpassword); $query= "UPDATE user_info SET password='".$newpassword."' WHERE id='$_SESSION[id]'"; mysql_query($query); session_start(); $_SESSION['status']="Password Successfully Changed"; $_SESSION['mail']="positive"; include("mail/pasword_change_verify_mail.php"); header('location:change_password.php?via=security_question'); die(" "); } and code of tp 5 line is : Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) { header('Location: login.php'); die (" "); } "BACK" or REFRESH: Preventing database interaction / code execution how to prevent database interaction / code execution when user presses back or refresh button? can i detect? can i disable back/refresh? Hi All, I'm having trouble with an email I'm trying to send out. While testing my code, the email that my script sends has the "Reply-To" email address in the headers but when I click "reply", the recipient's email, $to in the code below, is inserted instead of the "Reply-To" email. Am I missing anything? Thanks for the help in advance! $to = "abc@email.com"; $headers = "From: " .$admin_name. "<" .$admin_email. ">\r\n"; $headers .= "Reply-To: " .$host_name. "<" .$host_email. ">\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "<br>"; $subject = "Subject"; $body = "Body"; mail($to, $subject, $body, $headers); Hi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. I am able to retain values if I use the code Code: [Select] <form action="add_entry2.php" name="eval_edit" method="post" format="html"> i,e if I submit back to the same page and retrieve values form $_POST but If I use the code Code: [Select] <input type="button" value="Back" onClick="history.go(-1);return true;">to get back to add_entry2.ph it looses all the values. Is there any other way to code the BACK link retaining my $_POST values(Do you think $_SESSION would work in this case?) Why do i get this error when i put code for redirection on my php code :S Warning: Cannot modify header information - headers already sent by (output started at /home/dotars/public_html/shop/includes/functions.php:3) in /home/dotars/public_html/shop/includes/functions.php on line 20 This is that code on functions.php on line 20: function confirm_logged_in() { if (!logged_in()) { redirect_to("login.php"); } } function redirect_to($location = NULL) { if ($location != NULL) { header("Location: {$location}"); exit; } } And this is the code in the other php code: <?php require_once("includes/session.php"); ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <center> Text... </center> </body> </html> And confirm_logged_in() function is: <body background="homebackground.jpg"> <style type="text/css"> <!-- A:link { COLOR: black; TEXT-DECORATION: none; font-weight: normal } A:visited { COLOR: black; TEXT-DECORATION: none; font-weight: normal } A:active { COLOR: green; TEXT-DECORATION: none } A:hover { COLOR: blue; TEXT-DECORATION: none; font-weight: none } --> </style> <?php include ("database.php"); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = mysql_real_escape_string( $_COOKIE['ID_my_site'] ); $pass = mysql_real_escape_string( $_COOKIE['Key_my_site'] ); $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$pass'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass == $info['password']) print("<meta http-equiv='Refresh' content='0;index.php' />"); } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) die(' <body background="homebackground.jpg"><center><p><br><p><b> You did not fill in a required field, <a href="login.php"><b> click here to try again.</a></center></b></b> '); // checks it against the database if (!get_magic_quotes_gpc()) $_POST['email'] = addslashes($_POST['email']); $_POST['username'] = stripslashes($_POST['username']); $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) die(' <body background="homebackground.jpg"><center><p><br><p><b> That user does not exist in our database, <a href=add.php><b> click here to Register</a></b></b></center> '); while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) die(' <body background="homebackground.jpg"><center><p><br><p><b> Invalid password, <a href="login.php"><b>click here to try again.</b></b></a> '); else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $_POST['password'] = stripslashes($_POST['password']); $hour = time() + 3600; setcookie("ID_my_site", $_POST['username'], $hour); setcookie("Key_my_site", $_POST['pass'], $hour); //then redirect them to the members area if ($pass == $info['password']) print "you have logged in."; print("<meta http-equiv='Refresh' content='0;index.php' />"); } } } else { // if they are not logged in ?> <?php include ("nav.php"); ?> <center> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1> Log in</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> </center> <?php } ?> <HTML> <HEAD> <link rel="favicon.ico" href="***/favicon.ico"> <title> My site </title> </HEAD> <BODY> I understand the warning, but I don't get the issue on my local server, only on my live server. From what I can see in the outputted source is a space and also i'm assuming a newline, before the warning... I've traced every route in my code, no output what-so-ever. I can't believe the hosts would insert such characters. I've tried separate files within the root directory, an html and a php, neither output these characters. Eventually I commented out the inclusion of modules one by one and found that the error should be in a specific one of these... Now going through I can't find any 'echo' or 'print' statements. Everything is within functions, and this error happens before anything is called, just included. There are no erroneous spaces before or after php code tags. What else would / could produce output? (and why no issue on local server?) EDIT: There is no use of 'output buffering' either... I get an error stating that I cannot modify header information when I try to add a title to my login page. Here's <?php session_start(); require_once("includes/dbconn.php"); include("includes/htmlheader.php"); mysql_select_db(center); $user = $_POST['username']; $pass = $_POST['password']; $sql = "select username, password from users"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $isuser = $row['username']; $ispass = $row['password']; if(isset($_POST['submit'])){ if(($user==$isuser)&&($pass==$ispass)) { $_SESSION['username'] = $user; header("Location: home.php"); }else{ echo "Invalid Username or Password"; } } ?> The htmlheader.php has the title string. Help is appreciated So I have a login box in my header, which worked when i hosted it locally, but now everytime i try to login i get Cannot modify header information - headers already sent (output started at /home/content/06/7711706/html/index.php:15) in /home/content/06/7711706/html/includes/header.php on line 102 and 103 Which is the setcookie bit, not sure what i'm doing wrong though. Any idea what i'm doing wrong? Thanks Code: [Select] <?php include('variables/variables.php'); ?> <div id="header"> <?php include('includes/flash.php'); ?> <?php mysql_connect("XXXXXXXXX", "XXXXXXX", "XXXXXX") or die(mysql_error()); mysql_select_db("XXXXXXX") or die(mysql_error()); if(isset($_COOKIE['test'])) { $username = $_COOKIE['test']; $pass = $_COOKIE['pass']; $check = mysql_query("SELECT * FROM customers WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } $check = mysql_query("SELECT * FROM customers WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=reg.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(test, $_POST['username'], $hour); setcookie(pass, $_POST['pass'], $hour); header("Location: members.php"); } } } else { ?> <form action="<?php echo $_SERVER['includes/PHP_SELF']?>" method="post"> <table bgcolor="#6699FF" height="50" border="0" style="border:hidden" align="right"> <tr><td colspan=2 align="center"><h2>Login</h2></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?></div> Hello,
I have an error on multiple pages which looks much like this. If anyone can help that would be gratefully appreciated. I would also like to ask if you may give me an explanation as to why it is occurring and not just a solution. Also when I take the second header out the error disappears.
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\blog\blog_display_post.php:47) in C:\xampp\htdocs\blog\comments.php on line 49
Here is my code:
if(strlen($email) > 5){
mysqli_query($con, "INSERT INTO emails (email) VALUES ('$email')"); I am getting this error when I use this Code: [Select] header("Location: /"); to redirect to home page.I believe there is a javascript alert which come before this is called, that gives the below error, I cannot remove the alert so is there nay other way I can go about redirecting without giving me the below error ? Code: [Select] A PHP Error was encountered Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /home/dsdsd/application/core/MY_Controller.php:dsdsds) <?php header('Refresh: 5; URL=http://www.miraculousmedalapostolate.com'); exit(); ?> i dont know what to do with this! i have tried using other hosting and the code was working fine... please help me, i have been stuck on this problem for 2 days now. So last night I was changing the amount of posts I wanted on my Thesis Themed Wordpress blog. I went to click the Save button within wordpress and got this message on the next page. "Warning: Cannot modify header information - headers already sent by (output started at /home/content/50/8403650/html/wp-content/themes/thesis_18/custom/custom_functions.php:2) in /home/content/50/8403650/html/wp-includes/pluggable.php on line 934" Now my nav menu doesn't show up and when I go to archives, it gives me the same warning. Can someone please help me with this? Any help would be appreciated. I've added both custom_functions.php and pluggable.php as an attachment, I don't think it has anything to do with pluggable but added just in case. Thanks for your help. Briannyc [attachment deleted by admin] |