Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $dbHost = 'gznster';
  4. $dbUser = 'root';
  5. $dbPass = '123';
  6.  
  7. $GLOBALS['dbConn'] = @odbc_connect("Driver={SQL Server};Server={$GLOBALS['dbHost']};",$GLOBALS['dbUser'],$GLOBALS['dbPass']) or die('Database Connection Error!');
  8. if(!$GLOBALS['dbConn']){
  9.     exit("Connection failed:".odbc_errormsg());
  10. }
  11. // initializing variables
  12. $username = "";
  13. $email    = "";
  14. $errors = array();
  15.  
  16. $serverName = "gznster";
  17. $connectionInfo = array( "Database"=>"registration", "UID"=>"root", "PWD"=>"123");
  18. $conn = sqlsrv_connect( $serverName, $connectionInfo);
  19.  
  20.  
  21.  
  22.  
  23.  
  24. // REGISTER USER
  25. // LOGIN USER
  26. if (isset($_POST['reg_user'])) {
  27.   //$username = mysqli_real_escape_string($db, $_POST['username']);
  28. $username = isset($_POST['username']) ? trim($_POST['username']) : '';
  29.  
  30.  
  31.   if (empty($username)) {
  32.     array_push($errors, "Username is required");
  33.     //$errors[] = 'Please provide a user name.';
  34.   }
  35.  
  36.  
  37.   if (count($errors) == 0) {
  38.       $query = "SELECT * FROM registration.registation.databaseusers WHERE username=?";
  39.     //$results = mysqli_query($db, $query);
  40.     $stmt = odbc_prepare($GLOBALS['dbConn'],$query);
  41.   $args = array($username);
  42.         if(!odbc_execute($stmt,$args)){
  43.             $errors[] = 'Failed to determine if this username already exists in the database.';
  44.         }elseif($row = odbc_fetch_array($stmt)){
  45.             $errors[] = 'User name already exists, please choose a different user name.';
  46.         }
  47.    
  48.    
  49.     //insert username into events
  50.         $oko = "INSERT INTO users (username, email)
  51.               VALUES('$username', '$email')";
  52.     //mysqli_query($db, $oko);
  53.    
  54.     $stmt = odbc_prepare($GLOBALS['dbConn'],$oko);
  55.    
  56.     $_SESSION['username'] = $username;
  57.  
  58.     $monol = "UPDATE users INNER JOIN databaseusers USING (username) SET users.email = databaseusers.email";
  59.   //    mysqli_query($db, $monol);
  60.     $stmt = odbc_prepare($GLOBALS['dbConn'],$monol);
  61.    
  62.     //ijij
  63.    
  64.  
  65.     // if (mysqli_num_rows($results) == 1) {
  66.       // $_SESSION['username'] = $username;
  67.    
  68.     // $_SESSION['success'] = "You are now logged in";
  69.   //      header('location: index.php');
  70.   //    }else {
  71.   //        array_push($errors, "Wrong username/password combination");
  72.  //     }
  73.     $_SESSION['username'] = $username;
  74.         $sql = "INSERT INTO PS_UserData.dbo.Users_Master
  75.                 (UserID,Pw,JoinDate,Admin,AdminLevel,UseQueue,Status,Leave,LeaveDate,UserType,Point,EnPassword,UserIp)
  76.                 VALUES (?,?,GETDATE(),0,0,0,0,0,GETDATE(),'N',0,'',?)";
  77.         $stmt = odbc_prepare($GLOBALS['dbConn'],$sql);
  78.         $args = array($username);
  79.         if(odbc_execute($stmt,$args)){
  80.             $_SESSION['success'] = "You are now logged in";
  81.     header('location: index.php');
  82.   }else {
  83.         array_push($errors, "Wrong username/password combination");
  84.  }
  85.         }
  86.     }
  87.    
  88.  
  89.    
  90.    
  91.    
  92.  
  93.  
  94.  
  95. // ...
  96.  
  97.  
  98. // ...
  99.  
  100. // LOGIN USER
  101. if (isset($_POST['login_user'])) {
  102.   $username = mysqli_real_escape_string($db, $_POST['username']);
  103.  
  104.  
  105.   if (empty($username)) {
  106.     array_push($errors, "Username is required");
  107.   }
  108.  
  109.    
  110.  
  111.   if (count($errors) == 0) {
  112.  
  113.     $query = "SELECT * FROM users WHERE username='$username'";
  114.     $results = mysqli_query($db, $query);
  115.    
  116.    
  117.     //insert username into events
  118.         $oko = "INSERT INTO event (username, email)
  119.               VALUES('$username', '$email')";
  120.     mysqli_query($db, $oko);
  121.     $_SESSION['username'] = $username;
  122.  
  123.   //set similar rows in EVENT
  124.   $monol = "UPDATE event INNER JOIN users USING (username) SET event.email = users.email";
  125.     mysqli_query($db, $monol);
  126.    
  127.    
  128.     //
  129.      $monoll = "delete from ac";
  130.     mysqli_query($db, $monoll);
  131.    
  132.      $monolll = "insert into ac select username,count(username) from event group by username";
  133.     mysqli_query($db, $monolll);
  134.    
  135.  
  136.  
  137.    
  138.     //ijij
  139.    
  140.  
  141.     if (mysqli_num_rows($results) == 1) {
  142.       $_SESSION['username'] = $username;
  143.    
  144.     $_SESSION['success'] = "You are now logged in";
  145.       header('location: index.php');
  146.     }else {
  147.         array_push($errors, "Wrong username/password combination");
  148.     }
  149.    
  150.    
  151.    
  152.  
  153.    
  154.    
  155.    
  156.   }
  157. }
  158.  
  159. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement