munk.me.uk forum
May 21, 2012, 05:13:29 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Help with Redirect after checkPass function  (Read 1711 times)
bmalex1
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 3


View Profile Email
« on: May 24, 2008, 07:25:12 pm »

Greetings again forum,

I am trying to redirect the user to a diferent page other than members.php. I want to check the paid field in the database to see if it is yes or no. If it is "yes" then the user can go to members.php, if it is "no" then I want the user to go to another page called options.php. I tried this.....
Code:
function checkPass($login, $password) {
/*
Password checking function:
This is a simple function that takes the $login name and
$password that a user submits in a form and checks that a
row exists in the database where:

the value of the 'login' column is the same as the value in $login
and
the value of the 'password' column is the same as the value in $password

If exactly one row is returned, then that row of data is returned.
If no row is found, the function returns 'false'.
*/
global $link;

$query="SELECT login, password FROM clients WHERE login='$login' and password='".md5($password)."'";
$result=mysql_query($query, $link)
or die("checkPass fatal error: ".mysql_error());

// Check exactly one row is found:
if(mysql_num_rows($result)==1) {
$row=mysql_fetch_array($result);
return $row;
}
$row=$paid;

if($paid!="Yes")
{
header("location=option.php");
}
//Bad Login:
return false;
} // end func checkPass($login, $password)
but it didn't work !!! Which shows that I do need help.
Can someone please tell me how to do this??

Thanks
Logged
munk
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 368


View Profile WWW
« Reply #1 on: May 24, 2008, 08:08:36 pm »

You don't have any code to extract the paid data from the db:
Code:
// $query="SELECT login, password FROM clients WHERE login='$login' and password='".md5($password)."'";
// Extract paid column from db:
$query="SELECT login, password, paid FROM clients WHERE login='$login' and password='".md5($password)."'";
$result=mysql_query($query, $link)
or die("checkPass fatal error: ".mysql_error());

// Check exactly one row is found:
if(mysql_num_rows($result)==1) {
$row=mysql_fetch_array($result);
// *HERE*
// Do your $paid variable asignment here:
// make sure it's global first so other code can read it outside this function:
global $paid;
$paid = $row['paid']; // asumes that there's a column called 'paid' that contains the paid data in the same table as the user and password details - ideally it should be in another table but you can do that later!

return $row;
}

// This won't work because if the user logs in ok, the function returns to the calling procedure marked *HERE* above
// Instead you need to assign the $paid variable above where it's marked *HERE*:
// $row=$paid;
Logged

~ Jez
bmalex1
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 3


View Profile Email
« Reply #2 on: May 24, 2008, 09:33:52 pm »

Hi munk,
thanks for the reply. I am not sure I follow you.. here is what I have........................
Code:

function checkPass($login, $password) {
/*
Password checking function:
This is a simple function that takes the $login name and
$password that a user submits in a form and checks that a
row exists in the database where:

the value of the 'login' column is the same as the value in $login
and
the value of the 'password' column is the same as the value in $password

If exactly one row is returned, then that row of data is returned.
If no row is found, the function returns 'false'.
*/
global $link;

$query="SELECT login, password, paid FROM clients WHERE login='$login' and password='".md5($password)."'";
$result=mysql_query($query, $link)
or die("checkPass fatal error: ".mysql_error());

// Check exactly one row is found:
if(mysql_num_rows($result)==1) {
$row=mysql_fetch_array($result);

global $paid;
$paid = $row['paid']; // asumes that there's a column called 'paid' that contains the paid data in the same table as the user and password details - ideally it should be in another table but you can do that later!

return $row;
}

if($row['paid']!="Yes")
{
header("location=option.php");
}

//Bad Login:
return false;
} // end func checkPass($login, $password)

Where am I going wrong??
Logged
munk
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 368


View Profile WWW
« Reply #3 on: May 25, 2008, 01:28:12 am »

Ok, make sure you have this:

Code:
$query="SELECT paid, login, password, paid FROM clients WHERE login='$login' and password='".md5($password)."'";

and then leave the rest as it is in that checkpass func.

Then in the bit where you call checkPass(), I forget what it looks like now, can't be bothered to look it up, something like:

$row = checkpass();

make it like:

Code:
$row = checkpass();
if($row['paid'] == "whatever"){
header("location: http://example.com/");
} else {
// do whatever for if they haven't paid
}

Obviously change the location to whatever your url is for the ppl that have paid.  Check the php help for info like http://php.net/header Smiley
Logged

~ Jez
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!