471,616 Members | 1,315 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

New window opening for checking the authentication in the login form

Hi All,

I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i even tried with echo also how to solve this the message should come under in the same window only see my code it is
program
----
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Connects to your Database
  3.  
  4.  
  5. mysql_connect('localhost', 'root', 'epara') or die(mysql_error());
  6. mysql_select_db('mysql') or die(mysql_error()); 
  7.  
  8.  
  9. //This code runs if the form has been submitted
  10. if (isset($_POST['submit'])) {
  11.  
  12. //This makes sure they did not leave any fields blank
  13. if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
  14. die('You did not complete all of the required fields' );
  15. include "registration.php";
  16.  
  17. //header('Location:registration.php');
  18.  
  19. }
  20.  
  21. // checks if the username is in use
  22. if (!get_magic_quotes_gpc()) {
  23. $_POST['username'] = addslashes($_POST['username']);
  24. }
  25. $usercheck = $_POST['username'];
  26. $check = mysql_query("SELECT username FROM login WHERE username = '$usercheck'")
  27. or die(mysql_error());
  28. $check2 = mysql_num_rows($check);
  29.  
  30. //if the name exists it gives an error
  31. if ($check2 != 0) {
  32.  
  33. die( ' <b> Sorry, the username '.$_POST['username'].' is already in use. To Register <a href="registration.php">Please Click Here </b></a>  ');
  34. //header("Location:index.php");
  35. }
  36.  
  37. // this makes sure both passwords entered match
  38. if ($_POST['pass'] != $_POST['pass2']) {
  39. die(' <b> Your passwords did not match. To Register <a href="registration.php"> Please Click Here </b></a> ');
  40. //    header("Location:index.php");
  41. }
  42.  
  43. // here we encrypt the password and add slashes if needed
  44. $_POST['pass'] = md5($_POST['pass']);
  45. //$_POST['pass'] = ($_POST['pass']);
  46.  
  47. if (!get_magic_quotes_gpc()) {
  48. $_POST['pass'] = addslashes($_POST['pass']);
  49. $_POST['username'] = addslashes($_POST['username']);
  50. }
  51.  
  52. // now we insert it into the database
  53. $insert = "INSERT INTO login (username, password)
  54. VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
  55. $add_member = mysql_query($insert);
  56. ?>
  57.  
  58.  
  59. <h1>Registered</h1>
  60. <p>Thank you, you have registered - you may now login <a href="index.php"> Login </a>.</p>
  61.  
  62. <?php
  63. }
  64. else
  65. {
  66. ?>
  67. <html>
  68. <body>
  69. <table cellpadding="0" cellspacing="0" border="0">
  70. <tr valign="baseline">
  71.       <td>
  72.       <div align="left"><img src="images/home_masthead.gif" width="141" height="67"/></div></td>
  73.       <td width="212" align="center"></td>
  74.       <td width="371" align="right" valign="baseline"></td>
  75.       </tr>
  76.       </table>
  77.       <table cellpadding="0" cellspacing="0" border="0" align="right" valign="top">
  78.  
  79.   <tr>
  80.   <td><a href="index.html"><img src="images/nav_images/home.gif" alt="Home" border="0"/></a></td>
  81.   <td><a href="registration.php"> 
  82.     <img src="images/nav_images/company_sec.gif" alt="Registration" border="0"/></a></td>
  83.     <td><a href="login.php"> 
  84.     <img src="images/nav_images/careers_sec.gif" alt="Login" border="0"/></a></td>
  85.   </tr>
  86.   </table><br><br><br>
  87. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  88. <p><b> Registration form please fill all the fields</b></p>
  89. <table border="0">
  90. <tr><td><b>Username:</b></td><td>
  91. <input type="text" name="username" maxlength="60">
  92. </td></tr>
  93. <tr><td><b>Password:</b></td><td>
  94. <input type="password" name="pass" maxlength="10">
  95. </td></tr>
  96. <tr><td><b>Confirm Password:</b></td><td>
  97. <input type="password" name="pass2" maxlength="10">
  98. </td></tr>
  99. <tr><td></td></tr>
  100. <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
  101.  
  102. <tr><td></td></tr>
  103. </table>
  104. </form>
  105. </html>
  106. <br><br><br><br>
  107. <div class="small_text" align="center"><b>@</b><b>2008 Paradigm Consulting, Inc. All rights reserved.<b></div>
  108. </body></html>
  109. <?php
  110. }
  111. ?> 
  112.  
---
when running this it is going to different page the authentications please suggest me the answer as early as possible this whole code is in one page only not in separate pages.

Thanks in Advance,
Geeta
Nov 7 '08 #1
1 1886
nathj
938 Expert 512MB
You need to post code in code tags! It makes easier to read, more importantly it's the rules.
Nov 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Display Name | last post: by
reply views Thread by Scott | last post: by
3 posts views Thread by Kris van der Mast | last post: by
1 post views Thread by David Krussow | last post: by
6 posts views Thread by Manny Chohan | last post: by
6 posts views Thread by Ming Zhang | last post: by
1 post views Thread by noor | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.