Functions Problems

Functions Problems

Posted by: broknspyrl
Posted on: 2006-09-21 12:01:00

Hi i have a script and i have included a file to the page. i am working in PHP and i have a function check_keve($user,$pass,$level) and when i pass the variables to the function the page hangs:
http://www.intouchmusic.net/?go=login
user: test
pass: n0rtel
it just hangs out and i don't know why.

The function on the included page does an SQL lookup and the coding is sound as it works on every other server i test it on, just not on my DH server, any ideas?!?!!? help me

some of the code lol sorry:

function get_user_info($user)
{
$query = mysql_query("SELECT * FROM cmu06 WHERE uname = '$user'");
$rows = mysql_fetch_array($query);
return $rows;
}
function check_level($user,$pass,$level)
{
$user_info = get_user_info($user);
$query = mysql_query("SELECT * FROM cmug06 WHERE cmuid = '$user_info[id]' AND cmgid = '$level'");
$numrows = mysql_num_rows($query);
return $numrows;
}


These two functions are from the takelogin.php file, below is code from the index.php file:

<?PHP
include '../takelogin.php';
$username = $_COOKIE['USER_NAME'];
$password = $_COOKIE['PASS'];
$check = check_level($username,$password,1);



echo $check;
?>
i use the function to return if the username exists, in numerical value so i can pass to an if statement to determine what is shown to logged in users, admin users and logged out users
any help again would be very much appreciated
Regards,
Chris.


//EDIT//

MySQL dump of the two tables used:

CREATE TABLE `cmu06` (
`id` int(11) NOT NULL auto_increment,
`uname` text NOT NULL,
`md5pwd` text NOT NULL,
`email` text NOT NULL,
`regdate` date NOT NULL,
`confcode` text NOT NULL,
`active` int(1) NOT NULL default '0',
`regip` text NOT NULL,
`reghost` text NOT NULL,
`lastlogindate` text NOT NULL,
`lastloginip` text NOT NULL,
`ugroup` int(11) NOT NULL default '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM

and

CREATE TABLE `cmug06` (
`id` int(11) NOT NULL auto_increment,
`cmuid` text NOT NULL,
`cmgid` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM

It could be as simple as i missed out a letter or mispelled something and i'm not seeing it, but i don't know and i'm so frustrated haha!
The MySQL Connection function works perfectly as you can login which is another function contained in takelogin.php

Regards,
Chris.


Edited by broknspyrl on 09/21/06 02:33 PM (server time).

Re: Functions Problems

Posted by: rlparker
Posted on: 2006-09-21 12:09:00

It looks like the variables are not being properly passed, and given that you indicate the function works on other servers, I suggest you check which version of PHP you are using.

PHP 4.4.2 and PHP 5 handle passed variables differently wink.

--rlparker

Re: Functions Problems

Posted by: seiler
Posted on: 2006-09-21 12:10:00

You didn't include any code, so I don't think anyone will be able to help.

But simply guessing based on saying it works everywhere else, I'll guess that your trying to access MySQL as localhost instead of the correct hostname listed in your control panel.

Re: Functions Problems

Posted by: broknspyrl
Posted on: 2006-09-21 14:42:00

No, i updated the host to the correct host and the login function works perfectly and the DB connection is on the takelogin.php file, the login function is also in there so it connects no problems. This is why i'm stumped :|

Re: Functions Problems

Posted by: shelves
Posted on: 2006-09-21 15:05:00

You need to learn basic debugging. Put echo's in your code to see what your variables really are, instead of just looking at the code hoping you know what they are. You are looking for a point where you can say "at this point everything looks right; and here things are screwed up." Then keep narrowing the gap until you see the problem. You can put echo followed by exit to get arround the hang. You can echo your queries and run them yourself manually (you can copy and paste) and see what they are really returning.

Terry


Re: Functions Problems

Posted by: gordaen
Posted on: 2006-09-21 15:08:00

It looks like you are showing certain chunks of the code, but I'm not sure if you are editting out pieces. For instance, your check_level function does not use the $pass argument.

My personal guess is the problem is with this: cmuid = '$user_info[id]'

What is "id" ?

You could try creating your query as a string and echo it as a troubleshooting step.



Check out Gordaen's Knowledge, the blog, and the MR2 page.

Re: Functions Problems

Posted by: broknspyrl
Posted on: 2006-09-21 15:29:00

Now here's the thing, i now have ammended the function so it now reads:

function check_level($user,$level)
{
echo "SELECT * FROM cmug06 WHERE cmuid = 'hi' AND cmgid = '".$level."'";
}

So now when i call the function with this:

$test = check_level($user,1);

$test should say the final output of the function with the variables put in. Well, it still hangs... the $user_info[id] part is the UID pulled from a different function, however in the new function it still hangs and it doesn't seem to want to pass the variables which is why i'm thinking the scripts don't do it correctly :S?

Re: Functions Problems

Posted by: shelves
Posted on: 2006-09-21 16:20:00

Is that your whole program?

If not, are you sure it's calling check_level()? Are you sure it's not something before or after calling it that's hanging?

If you put an echo 'about to call check_level'; exit(); before calling it, then you will know if it's calling it. If you switch and put the exit() after the call, you will know it's really hanging in check_level().

Terry


Tags: query mysqlmysql queryphp filelolhttpfetchsql