Guest User

Untitled

a guest
Jan 12th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. register page to check if user exist in sql server 2012 using ODBC and php
  2. <?php
  3. include 'core/database/conn.php';
  4. include 'includes/overall/header.php';
  5. // Process the POST data.
  6. if (isset($_POST['log22'])){
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9. $confirm_password = $_POST['confirm'];
  10. $email = $_POST['email'];
  11. //echo $getemail;
  12. //echo "<script>alert('The Email is already registered');</script>";
  13.  
  14. $id=md5(rand(1,123));
  15. $id='ADM'.strtoupper(substr($id,0,10));
  16.  
  17. $username = strtoupper($username);
  18. $password = substr(md5($password),0,9);
  19. $email = strtoupper($email);
  20.  
  21.  
  22. //header ('Location: register.php');
  23.  
  24. $sql = "INSERT INTO[ICPAK_FORMS].[dbo].[ICPAK$User Register](
  25. [ID],[Username],[Password],[Email])
  26. VALUES ('$id','$username','$password','$email')";
  27.  
  28. global $DBCONN;
  29. odbc_exec($DBCONN,$sql);
  30.  
  31. }
  32. ?>
  33. <h1>Register</h1>
  34.  
  35. <!----><script type="text/javascript" src="js/regform.js"></script>
  36. <form id="formreg" name="formreg" method="post" action="register.php" onSubmit="return regformValidation()">
  37. <ul>
  38.  
  39. <li>
  40. Username:<br/><input type="text" name="username" value="<?php //if(isset($_POST['username'])){ echo $_POST['username']; } ?>"/>
  41. </li>
  42. <li>
  43. Password:<br/> <input minlength="5" type="password" name="password" value="<?php //if(isset($_POST['password'])){ echo $_POST['password']; } ?>"/>
  44. </li>
  45. <li>
  46. Confirm Password:<br/><input type="password" name="confirm" value="<?php //if(isset($_POST['confirm'])){ echo $_POST['confirm']; } ?>" />
  47. </li>
  48. <li>
  49. E-mail<br/>
  50. <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email']; } ?>"/>
  51. </li>
  52. <li>
  53. <input type="submit" value="submit" /><input type="hidden" name="log22" id="log22" value="Login" /></td>
  54. </li>
  55. <li>
  56.  
  57. <table>
  58. <tr><td colspan="2">If you are registered click <a href="login.php">here</a> to Login</td><tr>
  59. </table>
  60. </li>
  61. </ul>
  62. </form>
  63. <?php include 'includes/overall/footer.php';?>
  64.  
  65. $sql_select = "select * from [ICPAK_FORMS].[dbo].[ICPAK$User Register] where [Username] = $username";
  66. $queryresult = odbc_exec($DBCONN,$sql_select);
  67. if ( odbc_num_rows($queryresult) > 0 ) {
  68. {
  69. // code for insert
  70. }
  71. else {
  72. // show error that username already exist.
  73. }
  74.  
  75. $result = odbc_exec( $connection, "SELECT username FROM users_table WHERE username like '$username' ");
  76. if ( odbc_num_rows($queryresult) > 0) {
  77. echo 'User with this name already exist.. Please select a different username';
  78. ....
  79. ....
  80. // your logic what you want to do after that
  81. }
  82. else{
  83. //Save and Register User
  84. }
Add Comment
Please, Sign In to add comment