database - php login form not working correctly -


i'm trying create simple login functionality it's not working, , i'm relatively new mysqli please bear me. want check if email address , password correct , if log user in. in advance.

here login code checks credentials:

updated code - added report , i'm getting internal server error

<?php  require_once 'connect.php'; mysqli_report(mysqli_report_all);   session_start();  if (!isset($_session['email'])) {  $e = trim($_request['email']); $email = $mysqli->real_escape_string($e); $p = trim($_request['password']); $password = $mysqli->real_escape_string($p);  /* if ($result = $mysqli->query("select email, password, user_id" .                                              " users" .                                              " email = '$email' , password = '$password'")) {     printf("select returned %d rows.\n", $result->num_rows); echo 'total results: ' . $result->num_rows;  } */  if ($stmt = $mysqli->prepare("select email, password, user_id users email=? , password=?")) {      /* bind parameters markers */     $stmt->bind_param("ss", $email, $password);      /* execute query */     $stmt->execute();      /* bind result variables */     $stmt->bind_result($email, $password);      /* fetch value */     $stmt->fetch();     if ($stmt->num_rows==1) {    $row = $stmt->fetch_assoc(mysqli_num);    $user_id = $row['user_id'];    $_session['user_id'] = $user_id;    $_session['email'] = $email;    header("location: home.php");      /* close statement */     $stmt->close(); } else {     printf("error message: %s\n", $mysqli->error); } /* if ($result->num_rows==1) { $row = $result->fetch_assoc(mysqli_num);    $user_id = $row['user_id'];  if ($query_group = $mysqli->query("select *" .                                                         " user_groups" .                                                         " user_id = '".$user_id."'")) {    //no more setcookie    $_session['user_id'] = $user_id;    $_session['email'] = $email; } else { echo 'did not work'; } } */      /* free result set */     // $result->close(); } }  ?> 

and here connect.php connect database:

<?php $mysqli = new mysqli("data", "username", "password", "db");  if($mysqli->connect_errno > 0){     die('unable connect database [' . $mysqli->connect_error . ']'); }  ?> 

did try remove 1 of brackets in end of ypur code. guess have remove 1 of them.


Comments

Popular posts from this blog

visual studio - vb.net filter binding source by time -

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -