In this loginvalid function which checks a user is logged in by finding the num of rows with username and pass supplied. (Should only be 1) It connects to the mysql to check this. To do this I connect to mysql with a connection string in connect.php page which looks like this. (User, Pass values changed)
Code: Select all
<?
$connect = mysql_connect ("localhost", "user", "******");
$dbname = "csweb_csweb";
?>I then have includes.php which has the following.
Code: Select all
<?php
include "connection.php";
include "user/user-class.php";
include "display/display-class.php";
?>Then in user-class.php which im trying to get a mysql connection working in I have.
Code: Select all
<?
class user
{
function loginvalid($username, $password)
{
$loginquery = "SELECT * FROM users WHERE usernarrme='$username' AND password='$password' ";
print "$GLOBALS[dbname]";
$loginresult = mysql_db_query($GLOBALS[dbname], '$loginquery', $GLOBALS[connect]);
$loginvalid = mysql_num_rows($loginresult);
if ($loginvalid == "1") {
return 1;
}
else {
return 0;
}
}
}
$user = new user;
?>csweb_csweb
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/csweb/public_html/user/user-class.php on line 9
0
Its printing the dbname fine which confuses me why it wont connect as the connect variable should also work...
Also how can a classes function be accessed in another classes function is it possible.
Please please please help, Chris