Mysql php checking paid field
Moderator: General Moderators
Mysql php checking paid field
I have a site im making that will have users for a game, and i added a field called paid, so people who have paid for their account can access certain pages, i was just wondering how i could go about to code a page that lets only people who have the field value of Paid to Yes to view the contents.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah | Please use
thats my code, and it refers everyone to paidonly.php (a page that lets non-paid users know that they cannot access the site).
I set my account to paid, and it keeps referring me.
just to know, the top.php is nothing more than accessing the database.
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
ob_start();
//include some stuff
require("top.php");
if($_SESSION['Paid'] !== "Yes") {
header("Location: paidonly.php");
exit;
}
?>I set my account to paid, and it keeps referring me.
just to know, the top.php is nothing more than accessing the database.
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]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Code: Select all
<?php
/**
* If you do not need output buffering don't use it
* Replaced ob_start() with session_start()
**/
session_start();
// include db abstractions
require("top.php");
if (!isset($_SESSION['Paid']) || $_SESSION['Paid'] != "Yes") {
header("Location: http://www.usefullurlswithheader.com/paidonly.php");
exit;
}
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
OK, before you do any includes or redirects, run just this portion of code in its own page and post back the output.
Code: Select all
<?php
session_start();
echo '<h1>The session id is ' . session_id() . '</h1>';
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?>Code: Select all
The session id is 83aa8b8a1355dcc183c5b15b6d1ae385Array
(
[Uname] =>
[lp] =>
[admin_in] => 1
[admin_id] => 1
[admin_user] => Cyril
[admin_name] => Grant Kessler
[admin_lastlogin] => 1154609852
)- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah | Please use
?
Everah | Please use[/syntax]
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]
So something like this in the query?
[syntax="sql"]INSERT INTO loginphp(
Paid
)
VALUES (
'`Paid`'
)Everah | Please use[/syntax]
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]-
AshrakTheWhite
- Forum Commoner
- Posts: 69
- Joined: Thu Feb 02, 2006 6:47 am
Code: Select all
INSERT INTO `TableName` (`COLname1`, `COLname2`) VALUES(``, `value`) WHERE `UserIDTable`.UserID = $userIDIs it possible i can get an explaination of this? im self taught, so i dont know some things and known exactly how to do others. i know nothing about sessions really. I have a field called Paid already, but the session wont work, if that is the correctly way to make it work, can someone possibly give me an explanation of what to do following that example? :/ sorry guys. Im trying to learn though
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Can you post a MySQL Table structure dump so we can see your fields and field types? You may need to add a field to your user table, then you will need to update that field and when pulling user data upon login, grab the paid column and make a session var out of it.
But before all that, post your table structure.
But before all that, post your table structure.
Code: Select all
loginphp
Field Type Null Default
id int(11) No
Uname varchar(30) Yes NULL
Email varchar(30) Yes NULL
Fname varchar(30) Yes NULL
Lname varchar(30) Yes NULL
Pword varchar(30) Yes NULL
Kills int(11) No
Cname1 varchar(30) No
Cname2 varchar(30) No
Cname3 varchar(30) No
Deaths int(11) No
Drate int(11) No
Paid varchar(30) No
Indexes: Keyname Type Cardinality Field
PRIMARY PRIMARY 6 id- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I would maybe make paid a tinyint (1) field and have it be either a 1 or 0. Unpaid would be 0, paid would be 1. When you grab the users information upon login and set your session vars, add a session var called 'user_paid' to that list. Then, on each page, check it like this...
Code: Select all
<?php
session_start();
if (isset($_SESSION['user_paid']))
{
if ($_SESSION['user_paid'])
{
// Let me in!
}
else
{
header("Location: http://www.takemesomeplaceelse.com/");
exit;
}
}
?>