Aspies For Freedom

Full Version: Anyone really good at PHP Mysql?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

PHP Code:
<?php
//Database Information

$dbhost "localhost";
$dbname "loftyd_register";
$dbuser "loftyd_loftyd";
$dbpass "*********";

//Connect to database

mysql_connect $dbhost$dbuser$dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

session_start();
$username $_POST['Username'];
$password md5($_POST['Password']);

$query "select * from Users where Username='$username' and Password='$password'";
$result mysql_query($query) or die(mysql_error());
if (
mysql_num_rows($result) == 1)
{
    echo 
'Wrong Username and/or Password';
    include 
'login.html';

} else {
    
$_SESSION['username'] = '$username';
    include 
'characterprofile.php';
}

?>


That is code for authenticating users. However, if you type anything {eg: Username: Fredd_Bloggs Password: Freddy} it will go straight to the welcome screen. The data that you type to log in does not match with the information on the database. This would obviously say

PHP Code:
echo 'Wrong Username and/or Password'


But doesn't and goes straight to characterprofile.php

Is there anyone who can modify this so it works.
{PS: I'm having a go at making a web-based RPG. I'm doing the login atm. Your name will appear underneath the login page. }

Aw, I just realized how old this thread is. Oh well, I still want to say, two problems are with "if (mysql_num_rows($result) == 1)" and with "$_SESSION['username'] = '$username';".
The first one is testing the wrong condition. You want to test for <1, not ==1. The second one won't work because within single quotes, PHP won't insert the variable values. Use double quotes (") instead.
Reference URL's