Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373206
Share on other sites

^

^

 

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>

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373252
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373311
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1373529
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1374159
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/267696-pls-help-on-a-bug/#findComment-1374242
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.