Here is the one I was using before this "sample code" and it didnt seem to work either.. but I think this one is better structured than the sample one:
<?php
session_start();
include("functions.php");
$myConnection = connect();
if(isset($_POST['login'])){
if(isset($_SESSION['uid'])){
echo "You are already logged in!";
}else{
$username = ($_POST['username']);
$password = ($_POST['password']);
$login_check = mysqli_query($myConnection,"SELECT `id` FROM `user` WHERE `username`='$username' AND `password`='".md5($password)."'") or die(mysql_error());
if(mysqli_num_rows($login_check) == 0){
echo "Invalid Username and/or Password combination!";
}else{
$get_id = mysqli_fetch_assoc($login_check);
$_SESSION['uid'] = $get_id['id'];
$url = 'main.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
}
}else{
echo "";
}
?>
and function.php is where it connects to the DB:
<?php
$myConnection = connect();
function connect() {
return mysqli_connect("localhost","xxxxxxxx","xxxxxxxxx","xxxxxxxx");
}
function output($string) {
echo "<div id=\"output\">" . $string . "</div>";
}
?>
so somewhere between the two, I should be able to get it working.. use the .md5 and I noticed the first one is
"SELECT * FROM $tbl_name WHERE username='$myusername'
and the second:
"SELECT `id` FROM `user` WHERE `username`='$username'
should I be using SELECT * FROM or just SELECT `id` FROM ? <----- I think this also is where I might be getting screwed up because every table has a column for ID and Username.. or it may not have anything to do with it..