Okay, I'm really struggling to get to grasps with PDO, even after 2 days of trying to convert everything.
I'm now at the stage of creating an array for the $user_data['???']
And here's what I've got.
if (logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'id', 'username', 'password', 'email', 'active', 'coins');
$user_id = $user_data['id'];
if (user_active($user_data['username'] === false) {
session_destroy();
header('Location: index.php');
exit();
}
}
So that's my way of getting the data for $user_data['???']
The functions to go with it are..
function user_data($user_id){
$data = array();
$user_id = (int)$user_id;
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if ($func_num_args > 1) {
unset($func_get_args[0]);
$fields = '`' . implode('`, `', $func_get_args) . '`';
$data = //mysql_fetch_assoc(//mysql_query("SELECT $fields FROM `users` WHERE `user_id` = $user_id"));
return $data;
}
}
function user_active($username) {
$username = sanitize($username);
$query = //mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1");
return (//mysql_result($query, 0) == 1) ? true : false;
}
I'm pulling my hair out trying to figure out how to convert this into PDO, can anyone give me any help?
Also, after I do convert it to PDO. Would it be as simple for to say welcome the user with a simple message of Welcome <?php $user_data['username'] ?>, Hope you enjoy your stay!
or would I need to use a completely different method now?
Thanks in advance !
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…