im fairly new to php and am still trying to really get a hold of what im doing. right now im just trying to build a simple login function for my site and am completely stuck.
here is what i have so far.
in function authuser im trying to create a query, return the result, compare it with those that were posted on index.php and if it matches the database i would like the login function. to start the session.
i hope that makes sense.
and if there is a better way to do this or something im missing please let me know
index.php
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'];
$password = md5($_POST['password']);
if(empty($username) || empty($password)){
$data['status'] = 'Please fill out both inputs';
} else {
// login
authuser($username,$password);
}
}
functions.php
function login($username,$password)
{
session_start();
}
function authuser($username,$password)
{
$sql = "SELECT * FROM users WHERE username='$username' and password='$password'";
$results = mysql_query($sql);
$rows = mysql_num_rows($results);
if($rows==1)
{
session_register("admin");
} else {
echo "Wrong Username or Password";
}
}