Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. class conexion{
  3.  
  4. private $conexion;
  5. private $server = "localhost";
  6. private $usuario = "root";
  7. private $pass = "";
  8. private $db = "login";
  9. private $user ;
  10. private $password;
  11.  
  12. public function _construct(){
  13.  
  14. $this->conexion = new mysqli($this->server, $this->usuario, $this->pass, $this->db);
  15.  
  16. if ($this->conexion->connect_errno) {
  17.  
  18. die("Fallo al tratar de conectar con MYSQL: (".$this->conexion->connect_errno.")");
  19.  
  20. }
  21. }
  22.  
  23. public function cerrar(){
  24. $this->conexion->close();
  25. }
  26.  
  27. public function login($usuario, $pass){
  28.  
  29. $this->user = $usuario;
  30. $this->password = $pass;
  31.  
  32. $query = "select id, nombre, apellido, usuario, password from wisher where usuario = '".$this->user."' and password = '".$this->password."' ";
  33.  
  34. $consulta = $this->conexion->query($query); //error linea 34
  35.  
  36. if ($row = mysqli_fetch_array($consulta)) {
  37. # code...
  38.  
  39. session_start();
  40.  
  41. $_session['id'] = $row['id'];
  42. $_session['nom'] = $row['nombre'];
  43. $_session['ape'] = $row['apellido'];
  44.  
  45. echo "Has iniciado sesion";
  46.  
  47. echo $_session['id'];
  48. echo $_session['nom'];
  49. echo $_session['ape'];
  50.  
  51. }else {
  52. echo "usuario o contraseña incorrectos";
  53. }
  54.  
  55.  
  56.  
  57. }
  58.  
  59.  
  60. }
  61.  
  62. $c = new conexion;
  63. $c->login(...);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement