vinsux Posted August 28, 2012 Share Posted August 28, 2012 pls. help on my header... i tried to put up the the php code first but still.. it gives an error... i dont know what to do.. i'm sick of this error.. please help me to rearrange the right code to fix the error.. tnx in advance <?php session_start(); ?> <!DOCTYPE html> <html lang="en"> <?php include('include/header.php'); ?> <body> <?php include('include/fcontainer.php'); ?> <?php include('include/facultyleft.php'); ?> <?php include('include/panelfaculty.php'); ?> <div id="right"> <h3>Your Information</h3> <?php if(isset($_GET['delete'])) { $con = mysql_connect("localhost", "secret","secret"); if(!$con) { die("could not connect to server".mysql_error()); } mysql_select_db("ocmpq_login", $con); $result = mysql_query("SELECT * from faculty where username='$_GET[delete]'"); while($row = mysql_fetch_array($result)) { $sn = $row['username']; $nl = $row['namelast']; $nf = $row['namefirst']; $nm = $row['namemi']; $rm = "$row[namelast], $row[namefirst] has been removed from the site"; echo "<script type='text/javascript'>alert('$rm')</script>"; mysql_query("DELETE FROM faculty where username ='$_GET[delete]'"); header("Location: logout.php"); } mysql_close($con); } if(isset($_SESSION['id'])) { $username = $_SESSION['id']; $con = mysql_connect("localhost", "secret","secret"); if(!$con) {die("could not connect to server".mysql_error());} mysql_select_db("ocmpq_login", $con); $result = mysql_query("SELECT * from faculty WHERE username = '$username'"); $sql_num=mysql_num_rows($result); if($row = mysql_num_rows($result) == 0) { echo "There are no registered faculty yet<br><br>"; $name=$row["username"]; $class=$row["namelast"] .$row["namefirst"]; } else { while($sql_row = mysql_fetch_array($result)) { $name=$sql_row["username"]; $class=ucfirst($sql_row["namelast"]). ', ' .ucfirst($sql_row["namefirst"]). ' ' .ucfirst($sql_row["namemi"]); $gender=$sql_row["gender"]; $email=$sql_row["email"]; $course= $sql_row["course"]; $pass= $sql_row["password"]; echo "<table border = 0 style='background-image:url(images/test.png); cellpadding='0px'>"; echo "The Complete Information of <b>$class</b>."; echo "<br><br>"; echo "<hr>"; echo "<th width = 10%><b><br><br> Staff ID:</b> </th>"; echo "<th width = 70%><br><br>" .$name."</th></tr>"; echo "<br><br>"; echo "<th><b> Name:</b> </th>"; echo "<th>" .$class."</th></tr>"; echo "<th><b> Gender:</b> </th>"; echo "<th>" .$gender."</th></tr>"; echo "<th><b> Email:</b> </th>"; echo "<th>" .$email."<br><br><br><br></th></tr>"; echo "<th colspan=2 align=center><br> <a href=javascript:confirmDelete('?delete=$sql_row[username]')><img src='images/deactivate.png'></a></th>"; echo "</table>"; echo "<br><br><br><hr><br><br>"; } } } mysql_close(); ?> </div> </div> </div> <footer> <div id="privacy"> thesis Project ? 2012 Privacy Policy</a><br /> </div> </footer> </div> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/ Share on other sites More sharing options...
cunoodle2 Posted August 28, 2012 Share Posted August 28, 2012 What is the error message you are getting? Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373182 Share on other sites More sharing options...
PFMaBiSmAd Posted August 28, 2012 Share Posted August 28, 2012 please help me to rearrange the right code to fix the error.. The solution that will always work, is to put all your php logic first, producing content in php variables, then you output that content in your html document only at the end of the page. <?php session_start(); // php code that produces the content on the page - $main_navigation = "..........."; ... $login_content = ".........."; ... $main_content = "........."; ... // output the actual page ?> <!DOCTYPE html> <html lang="en"> <title>Typical page that produces the content above, then outputs it all at once in the HTML document -</title> <body> <div><?php echo $main_navigation; ?><div> <div><?php echo $login_content; ?><div> <div><?php echo $main_content; ?></div> </body> </html> By arranging the logic on your page this way, any php code that needs to redirect or set a cookie can do so, since it comes before you output anything on the page. This also has the affect of separating the main logic on your page that produces the content for the page from the html that defines the page layout. Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373206 Share on other sites More sharing options...
vinsux Posted August 28, 2012 Author Share Posted August 28, 2012 ^ ^ tnx sir.. i got the logic and the code for that.. but how about this one?? the content is in one declaration of if else.. so hard... There's still a header error.. i can't understand the logic on this code.. on how the header will be placed.. <?php session_start(); ?> <!DOCTYPE html> <html lang="en"> <?php include('include/header.php'); ?> <body> <?php include('include/container.php'); ?> <?php include('include/left.php'); ?> <?php include('include/panelstud.php'); ?> <div id="right"> <h3>Student Change Password</h3> <?php if(isset($_SESSION['id'])) { $username = $_SESSION['id']; if (isset($_POST['submit'])) { if(!$_POST['oldpassword'] | !$_POST['newpassword'] | !$_POST['repeatnewpassword']) { die('You did not fill in a required field...<a href=studchangepass.php>Back</a>'); } if (strlen($_POST['repeatnewpassword'])>32||strlen($_POST['repeatnewpassword'])<6) { die("<br /> *Password must be between 6 and 32 characters long... <a href=studchangepass.php>[back]</a>"); } $oldpassword = md5($_POST['oldpassword']); $newpassword= md5($_POST['newpassword']); $repeatnewpassword = md5($_POST['repeatnewpassword']); $connect = mysql_connect("localhost", "root","") or die ("couldnt connect to mysql data base "); mysql_select_db("ocmpq_login") or die("couldnt find db") ; $queryget = mysql_query("SELECT password FROM students WHERE username ='$username'") or die("query didnt work"); $row=mysql_fetch_assoc($queryget); $oldpassworddb=$row['password']; if ($oldpassword==$oldpassworddb) { if ($newpassword==$repeatnewpassword) { $querychange = mysql_query("UPDATE students SET password='$newpassword' WHERE username='$username'"); header("location:logout.php"); } else die ("New Password did not match! <a href=studchangepass.php>[try again]</a>"); } else die ("Your old password input did not match in your old pass! <a href=studchangepass.php>[try again]</a>"); } else echo " <form action='studchangepass.php' method='POST'> <table border = 0 align = center> <tr> <th width = 35%>Old password:</center></th><th><input type='password' name='oldpassword'></th></tr> <th width = 35%>New password:</th><th><input type='password' name='newpassword'><p></th></tr> <th width = 35%>Repeat new password:</th><th><input type='password' name='repeatnewpassword'></th></tr> <th colspan = 2 align = right><br><input type='submit' name='submit' value='change password' style='width: 150px; height: 30px'></th> </tr> </table> </form> "; } else die ("You must be logged in to change the password") ?> </div> </div> </div> <?php include('include/footer.php'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373252 Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 Are you quite sure you understood what PFMaBiSmAd wrote? Because you haven't implemented any of it. Move all of the PHP to the top of the page, and use variables to store the output instead of printing it out directly. In other words, make sure you've done all of your processing before printing out anything. That way you know exactly what to print, and you're not locked in by what you've sent to the browser previously. Not to mention using a message in die () after sending a Location header is pretty pointless, the user will never see the message because of the redirect. So don't redirect the user on errors, but re-populate the form and show it again (easy, if you're doing all of the processing first). Only when the user successfully submits a form should you redirect, and then to avoid the refresh=resend problem. Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373311 Share on other sites More sharing options...
hakimserwa Posted August 28, 2012 Share Posted August 28, 2012 also read about php output buffering Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373341 Share on other sites More sharing options...
Christian F. Posted August 28, 2012 Share Posted August 28, 2012 Output buffering is a band aid solution, and not recommended in this case. Proper separation of logic and presentation is the only correct course in this situation. Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373355 Share on other sites More sharing options...
PFMaBiSmAd Posted August 29, 2012 Share Posted August 29, 2012 EVERYTHING that is not inside of <?php ?> tags is treated as literal 'in-line' html on the page and is output to the browser as is, even the blank lines. Just one blank line or one character that is outside of <?php ?> tags will prevent headers from working. In your last code, lines 2,3,4,6,7,8,10,12,14,15,16, and 17 are all in-line html that is being output to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373529 Share on other sites More sharing options...
hakimserwa Posted August 31, 2012 Share Posted August 31, 2012 Output buffering is a band aid solution, and not recommended in this case. Proper separation of logic and presentation is the only correct course in this situation. Most especially for we bigginers, there comes a time when you either like it or not you have to use output buffering Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1374159 Share on other sites More sharing options...
Jessica Posted August 31, 2012 Share Posted August 31, 2012 Output buffering is a band aid solution, and not recommended in this case. Proper separation of logic and presentation is the only correct course in this situation. Most especially for we bigginers, there comes a time when you either like it or not you have to use output buffering No, you can actually use the right solution, and then be less of a beginner. Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1374242 Share on other sites More sharing options...
hakimserwa Posted August 31, 2012 Share Posted August 31, 2012 i agree its not the wright solution but it work when in a rush Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1374342 Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2012 Share Posted August 31, 2012 And even when you're in a rush, it's still a hack. Quote Link to comment https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1374345 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.