Mysql php checking paid field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

i set the field paid to a tinyint and set my account to 1, and tested with another account that has no paid value, and it still lets the person with no value on the page
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, post the code.
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
include("top.php"); 
//top.php is the database connection settings only, along with a welcome username and 3 image links
session_start(); 

if (isset($_SESSION['Paid'])) 
{ 
    if ($_SESSION['Paid']) 
    { 
        // Let me in! 
    } 
    else 
    { 
        header("paidonly.php"); 
        exit; 
    } 
}
Everah | Removed potentially sensitive information.


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, first thing, please use the appropriate bbCode tags when posting code. I have cleaned this up for you a few times.

Next, try this...

Code: Select all

<?php
include("top.php");
// top.php is the database connection settings only, 
// along with a welcome username and 3 image links

// Start the session here
session_start();

// First things first, check the paid session var
if (isset($_SESSION['Paid']))
{
    // Ok, the session var 'Paid is set
    if ($_SESSION['Paid'])
    {
        // Session var 'Paid' is true (or 1)
        // Let me in!
    }
    else
    {
        // Session var 'Paid is false (or 0)
        // Redirect to A FULL URL AS PER THE MANUAL
        header("Location: http://www.mysite.com/paidonly.php"); 
        exit;
    }
}
else
{
    // Session var 'Paid' is not set,
    // Redirect to A FULL URL AS PER THE MANUAL
    header("Location: http://www.mysite.com/paidonly.php"); 
    exit;
}
?>
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

its still sending me to the paidonly part of the site, and i have a 1 for paid. i think it might be that my session may not be set (i know nothing about sessions though)
how would i set up the session if its not?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post the code where you set all the other user session vars. I will put it into that code.
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

I think it was insterted with a query. Im not exactly sure, i used an extremely stripped login code, and modified it to how i wanted it to work.
Again, i dont know anything about sessions, so if this isnt them being set, i have no idea what to look for, and im sorry for a useless post. :/

INSERT INTO loginphp
(Uname, Email, Pword) VALUES('$ADMINUNAME', '$ADMINEMAIL', '$ADMINPWORD')
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Ok, lets simplify things a bit...

Usually, a login process consists of validation, authentication and/or access control. When a user is validated, session vars are set to include basic information about the user...

Code: Select all

<?php
session_start();
$user_validated = false;

// after the login checking and validation...
// maybe during the data fetch from the database
while ($row = mysql_fetch_array($result))
{
    $user_validated = true;
    $_SESSION['username'] = $row['username'];
    $_SESSION['userlevel'] = $row['userlevel';
    // This would be a great place to handle the paid var
    $_SESSION['userpaid'] = $row['userpaid'];
}

if ($user_validated)
{
    header("Location: http://www.mysite.com/goodlogin.php");
    exit;
}
else
{
    header("Location: http://www.mysite.com/badlogin.php");
    exit;
}
?>
This is an extremely stripped down method demonstration, but it should give the basic logic of what you want to do.
Last edited by RobertGonzalez on Sun Aug 06, 2006 11:55 pm, edited 1 time in total.
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

wow, im so retarded. i see it now. its easy lol. sorry, but thank you so much for sticking through and helping me, i really appreciate it. :) i will definitly refer people to this site to give input and output!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You're not retarded. You're new. We all started somewhere. Keep practicing. Heck, one day you may be here answering people's questions, too.
Post Reply