<head>
<?php
$db=mysql_connect("localhost","root","") or die ('Connection error'. mysql_error());
	echo "ajay<br/>";

mysql_select_db("chat") or die ('Error connecting to database'. mysql_error());
	echo "connected to database";

$fr_username=$_POST["txt_username"];
$fr_password=$_POST["txt_password"];

$result = mysql_query("SELECT username,password FROM login WHERE username='$fr_username' AND password='$fr_password' ");

while($row = mysql_fetch_assoc($result))
  {
 		if($result!="")  
			{
				echo "good";
			}
		else 
			{			
    			if ($result="")
					{
						echo "bad";
     				}
			}
} 

mysql_close($db);


$date = date("a");
if ($date=="am")
	{
		$title="Good Morning";
	}	
else
	{	
		$title="Good Afternoon";
	}


?>
</head>
<title>met-ene-dialogue</title>
<?php echo $title ?>
<style type="text/css">
<!--
body {
	background-image: url();
}
.style1 {color: #C13167}
.style2 {font-size: large}
-->
</style></head>

<body>
	
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th width="16%" bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145"/></th>
    <th width="77%" bgcolor="#FFCCFF" scope="col"><p class="style1">WELCOME</p>
    <p class="style1">TO </p>
    <p class="style1">METE-ENE-DIALOGUE DOT COM  </p></th>
    <th width="7%" background="Drag to a file to choose it." bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145" /></th>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#FFFFFF"><table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th width="50%" bordercolor="#330033" scope="col" border = "5">MEMBERS LOGIN </th>
        <th width="50%" bordercolor="#330033" scope="col">NEW USER? SIGN IN </th>
      </tr>
      <tr>
        <td height="139">
		<form action = "<?php $page?>" method ="post">
	      <p>Username: 
	        <input type = "text" name = "txt_username"/>
	       
	        </p>
	      <p>Password: 
	        <input type = "password" name = "txt_password"/>
	      </p>
	      <p>
	        <input name="Submit" type = "submit" value="Submit"/>
	              </p>
        </form></td>
        <td height="139" align="center" valign="middle"><span class="style2">Sign in as new user </span></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

hi! i need help! i created a code and sql db for store usere name and password, but i only doest the $result wen if found the username and password. help plz and also i want to open anothe page wen the username and password is ok! i used header, but it sent erorr that "cant modify header, already sent" plz help

Recommended Answers

All 5 Replies

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

header()

PS : Why do you put your code in HEAD ?

- Mitko Kostov

but i dont really know how to use them, could you plz explain in more clear words! plz

If you want to use header() you must write it before any html code.

<?php

// check if submit button is clicked

if (isset($_POST['submit']))

{
$db=mysql_connect("localhost","root","") or die ('Connection error'. mysql_error());
	echo "ajay<br/>";

mysql_select_db("chat") or die ('Error connecting to database'. mysql_error());
	echo "connected to database";

$fr_username=$_POST["txt_username"];
$fr_password=$_POST["txt_password"];

$result = mysql_query("SELECT username,password FROM login WHERE username='$fr_username' AND password='$fr_password' ");

while($row = mysql_fetch_assoc($result))
  {
 		if($result!="")  
			{
				header("Location: page1.php");
			}
		else 
			{			
    			if ($result="")
					{
						echo "bad";
     				}
			}
} 

mysql_close($db);

}

$date = date("a");
if ($date=="am")
	{
		$title="Good Morning";
	}	
else
	{	
		$title="Good Afternoon";
	}


?>
</head>
<title>met-ene-dialogue</title>
<?php echo $title ?>
<style type="text/css">
<!--
body {
	background-image: url();
}
.style1 {color: #C13167}
.style2 {font-size: large}
-->
</style></head>

<body>
	
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th width="16%" bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145"/></th>
    <th width="77%" bgcolor="#FFCCFF" scope="col"><p class="style1">WELCOME</p>
    <p class="style1">TO </p>
    <p class="style1">METE-ENE-DIALOGUE DOT COM  </p></th>
    <th width="7%" background="Drag to a file to choose it." bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145" /></th>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#FFFFFF"><table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th width="50%" bordercolor="#330033" scope="col" border = "5">MEMBERS LOGIN </th>
        <th width="50%" bordercolor="#330033" scope="col">NEW USER? SIGN IN </th>
      </tr>
      <tr>
        <td height="139">
		<form action = "<?php $page?>" method ="post">
	      <p>Username: 
	        <input type = "text" name = "txt_username"/>
	       
	        </p>
	      <p>Password: 
	        <input type = "password" name = "txt_password"/>
	      </p>
	      <p>
	        <input name="Submit" type = "submit" value="Submit"/>
	              </p>
        </form></td>
        <td height="139" align="center" valign="middle"><span class="style2">Sign in as new user </span></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

ok, y did u resend me the code? i used a javascript for that

<script language="javascript">
  top.location.replace("./a.php");
</script>

and its working fine! but the problem is that, it doeasnt do wen the username and password is not found! i mean the else part, y?

I don't understand you.

So, if the username and password are found
in DB the page redirects. What do you want
to do if it's incorrect ?

Hint: You can put $_SERVER in form action url to reload login page
until username and password are correct.


- Mitko Kostov

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.