Hey all,
i made login script and all works fine, but i have problem with getting username to show like Welcome Username. I dont know if i wrong in function or when i started a session here is code
// function for display username function user($username) { $username = sanitize($username); $query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"); $result = mysql_result($query, 0, 'username'); if ($result == true) { return true; } else { return false; } }
this is function and when i call it it doesn't show nothing, and here is login.php
<?php include 'core/init.php'; // check if user is logged if (!logged()) { if (isset($_POST['login'])) { $username = $_POST['username']; $password = $_POST['password']; if (isset($username) && isset($password)) { // check if username and password is entered if (empty($username) && empty($password)) { echo 'All fields are required'; // if username exist in database } else if (user_exist($username) === false) { echo 'Username with that username dont exist.'; // check if username and password match } else if (is_match($username, $password) === false) { echo 'Invalid username, password combination'; } else { // start session $_SESSION['user_id'] = 1; // redirect user to user page header('Location: logged.php'); exit(); } } } } else { header('Location: index.php'); exit(); } ?>
so do i must make query in login.php and take username and put in in session or i can put that in function ? Please help im new in php so... be gentle