Post Reply  Post Thread 
Anyone really good at PHP Mysql?
Author Message
LoftyD



Posts: 156
Group: Registered
Joined: Apr 2007
Status: Offline
Post: #1
Anyone really good at PHP Mysql?

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. }


Get a free email forward {???@loftyd.net}!
Sign up at http://www.loftyd.net to get one.

Also, have a sneak peak at my RPG game.

09-30-2007 02:03 PM
Visit this users website Find all posts by this user Quote this message in a reply
jayssite



Posts: 2
Group: Registered
Joined: Feb 2008
Status: Offline
Post: #2
RE: Anyone really good at PHP Mysql?

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.

02-01-2008 01:11 AM
Find all posts by this user Quote this message in a reply
avinmichal
Banned


Posts: 5
Group: Banned
Joined: Jul 2011
Status: Offline
Post: #3
RE: Anyone really good at PHP Mysql?

The aboriginal one is testing the amiss condition. You wish to analysis for <1, not ==1. The additional one will not plan because aural individual quotes, PHP will not admit the capricious values. Use bifold quotes (") instead.

07-01-2011 07:56 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: