User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,273 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,284 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 479 | Replies: 5
Reply
Join Date: Jul 2007
Posts: 20
Reputation: dmotah is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dmotah dmotah is offline Offline
Newbie Poster

Help login page problem again

  #1  
Aug 20th, 2007
<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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Location: Sofia, Bulgaria
Posts: 138
Reputation: MitkOK is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: login page problem again

  #2  
Aug 20th, 2007
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
Last edited by MitkOK : Aug 20th, 2007 at 4:23 am.
Reply With Quote  
Join Date: Jul 2007
Posts: 20
Reputation: dmotah is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dmotah dmotah is offline Offline
Newbie Poster

Re: login page problem again

  #3  
Aug 20th, 2007
but i dont really know how to use them, could you plz explain in more clear words! plz
Reply With Quote  
Join Date: Jul 2007
Location: Sofia, Bulgaria
Posts: 138
Reputation: MitkOK is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: login page problem again

  #4  
Aug 20th, 2007
If you want to use header() you must write it before any html code.

  1. <?php
  2.  
  3. // check if submit button is clicked
  4.  
  5. if (isset($_POST['submit']))
  6.  
  7. {
  8. $db=mysql_connect("localhost","root","") or die ('Connection error'. mysql_error());
  9. echo "ajay<br/>";
  10.  
  11. mysql_select_db("chat") or die ('Error connecting to database'. mysql_error());
  12. echo "connected to database";
  13.  
  14. $fr_username=$_POST["txt_username"];
  15. $fr_password=$_POST["txt_password"];
  16.  
  17. $result = mysql_query("SELECT username,password FROM login WHERE username='$fr_username' AND password='$fr_password' ");
  18.  
  19. while($row = mysql_fetch_assoc($result))
  20. {
  21. if($result!="")
  22. {
  23. header("Location: page1.php");
  24. }
  25. else
  26. {
  27. if ($result="")
  28. {
  29. echo "bad";
  30. }
  31. }
  32. }
  33.  
  34. mysql_close($db);
  35.  
  36. }
  37.  
  38. $date = date("a");
  39. if ($date=="am")
  40. {
  41. $title="Good Morning";
  42. }
  43. else
  44. {
  45. $title="Good Afternoon";
  46. }
  47.  
  48.  
  49. ?>
  50. </head>
  51. <title>met-ene-dialogue</title>
  52. <?php echo $title ?>
  53. <style type="text/css">
  54. <!--
  55. body {
  56. background-image: url();
  57. }
  58. .style1 {color: #C13167}
  59. .style2 {font-size: large}
  60. -->
  61. </style></head>
  62.  
  63. <body>
  64.  
  65. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  66. <tr>
  67. <th width="16%" bgcolor="#FFFFFF" scope="col"><img src="images/queascopf4.gif" width="124" height="145"/></th>
  68. <th width="77%" bgcolor="#FFCCFF" scope="col"><p class="style1">WELCOME</p>
  69. <p class="style1">TO </p>
  70. <p class="style1">METE-ENE-DIALOGUE DOT COM </p></th>
  71. <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>
  72. </tr>
  73. <tr>
  74. <td colspan="3" bgcolor="#FFFFFF"><table width="100%" border="1" cellspacing="0" cellpadding="0">
  75. <tr>
  76. <th width="50%" bordercolor="#330033" scope="col" border = "5">MEMBERS LOGIN </th>
  77. <th width="50%" bordercolor="#330033" scope="col">NEW USER? SIGN IN </th>
  78. </tr>
  79. <tr>
  80. <td height="139">
  81. <form action = "<?php $page?>" method ="post">
  82. <p>Username:
  83. <input type = "text" name = "txt_username"/>
  84.  
  85. </p>
  86. <p>Password:
  87. <input type = "password" name = "txt_password"/>
  88. </p>
  89. <p>
  90. <input name="Submit" type = "submit" value="Submit"/>
  91. </p>
  92. </form></td>
  93. <td height="139" align="center" valign="middle"><span class="style2">Sign in as new user </span></td>
  94. </tr>
  95. </table></td>
  96. </tr>
  97. </table>
  98. </body>
  99. </html>
Reply With Quote  
Join Date: Jul 2007
Posts: 20
Reputation: dmotah is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dmotah dmotah is offline Offline
Newbie Poster

Re: login page problem again

  #5  
Aug 20th, 2007
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?
Reply With Quote  
Join Date: Jul 2007
Location: Sofia, Bulgaria
Posts: 138
Reputation: MitkOK is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: login page problem again

  #6  
Aug 20th, 2007
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['PHP_SELF'] in form action url to reload login page
until username and password are correct.


- Mitko Kostov
Last edited by MitkOK : Aug 20th, 2007 at 7:22 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:38 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC