如何使用fetch assoc和fetch数组

时间:2017-03-05 15:02:32

标签: php mysql

我只是想知道谁登录到系统,所以我希望获得用户登录的位置并将他们带到他们的工作地点。我不知道如何使用fetch assoc或fetch数组,谢谢你提前帮助我..希望你理解大家并抱歉

$email = $_POST['email'];
$password = $_POST['password'];
$tableName = "";
$position = "";

function login($tableName)
{
    global $connect, $email, $password;
    $query = "SELECT * FROM " . $tableName . " WHERE email=? AND password=? LIMIT 1";
    $statement = mysqli_prepare($connect, $query);
    mysqli_stmt_bind_param($statement, "ss", $email, $password);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    $count = mysqli_stmt_num_rows($statement);
    mysqli_stmt_close($statement);
    $row = mysqli_fetch_array($statement);
    $data = mysqli_fetch_assoc($statement);    
    return ($count == 1);

}

if (login('tbl_users')) {

    $_SESSION['user'] = $row['email'];

    header('Location:../index.html');

} else if (login('tbl_gramusers')) {
    $row['position'];
    echo $row;

    //   header('Location:../stocks_index.html');
    //header('Location:../admin.html');     
} else {
    echo 'Wrong Username or password!';
}

0 个答案:

没有答案