i created a log in on my php, but cant seem to find the bug. need help finding it. below is my code:
my login.php
<?php
if(isset($_POST['U_Name']) && isset($_POST['U_Pass'])){
$user = $_POST['U_Name'];
$pass = $_POST['U_Pass'];
if(!empty($user) && !empty($pass)){
$query = mysql_query("SELECT * FROM accounts WHERE U_Name = '".$user."' AND U_Pass = '".$pass."'") or die (mysql_error());
$data = mysql_fetch_array($query);
$test = $data['U_Pass'];
$query_run = $query;
$query_num_rows = mysql_num_rows($query_run);
if($query_num_rows == 0){
echo "Invalid username/password";
}
else if($query_num_rows == 1){
echo "ok";
$user_id = mysql_result($query_run,0,'id');
$user_id = $data['U_ID'];
$_SESSION['user_id'] = $user_id;
header("location:".$_SERVER['PHP_SELF']." ");
}
{
}
}
else{
echo "You must supply a username and password";
}
}
?>
<div align = "center">
<form action ="<?php echo $current_file; ?>" method = "POST">
Username : <input type = "text" name = "username"> Password : <input type = "password" name = "password">
<input type = "submit" value = "Log in">
</form>
</div>
and connection.php:
<?php
$dbc = mysql_connect('localhost', 'root', '') or die ("Can't connect : ". mysql_error());
mysql_select_db('users', $dbc) or die ("Can't connect : ". mysql_error());
?>
whenever i input my username and password it would only just return to my login page. nothing happened, not even an error message. please help me. thanks