Forum Moderators: coopster
<?php
include 'open.php';
if( get_magic_quotes_gpc() ) {
$me=$_REQUEST['username'];
$pass=$_REQUEST['password'];
$me = str_replace( "'", "''", $me );
$pass = str_replace( "'", "''", $pass );
}
mysql_select_db($dbname) or die('Cannot select database');
$query = "SELECT * FROM users WHERE username = '$me' AND password = '$pass'";
$result = mysql_query($query);
$username=mysql_result($result,"username");
$password=mysql_result($result,"password");
$id=mysql_result($result,"id");
if ($username == $me && $password == $pass)
{
setcookie ("id1", $id,time()+36000);
setcookie ("name", $username,time()+36000);
header ('location: clanadmin.php');
}
else
{
header ('location: error.php');
}
include 'close.php';
;?>
Basically the part in bold is not working! I am not being forwared if the username and password match. I am sorry that this is simple to those who know MYSQL but I am completely new to it
No problem, we are here to help. Nothing is asumed as being easy if you don`t understand it.
Try changing:
$username=mysql_result($result,"username");
$password=mysql_result($result,"password");
$id=mysql_result($result,"id");if ($username == $me && $password == $pass)
to:
$row = mysql_fetch_object($result);
if ($row->username == $me && $row->password == $pass)
See if that helps.
dc
Also, before your closing PHP tag you have a rogue semi colon.
;?>
One more thing, the include at the end of your code isnt going to do anything because its called after the header functions.
$me and $pass were ok, they equaled...
admin and mypass
BUT the following is returning the wrong values..
$username=mysql_result($result,"username");
$password=mysql_result($result,"password");
it returns "1" and "1" when it should be returning "admin" and "mypass"
However, If for test purposes i try a simple select query and select the values that are in the table and use a while loop to display them then it works fine! but obviously i dont want a while loop. It just wont work when I use SELECT FROM WHERE and then try and use this data
..edit the values it returns (1 and 1) are the ID, it is therefore only reading column 1 (ID)
$username=mysql_result($result,"username");
$password=mysql_result($result,"password");
with
$record= mysql_fetch_assoc($result);
$username = $record['username'];
$password = $record['password'];
I hope thats correct and valid PHP!
Thanks for your help guys, I'm glad I'm now a step further away from microsoft!