SitePoint Sponsor |
|
User Tag List
Results 1 to 19 of 19
Thread: Help with a simple query
-
Jul 3, 2007, 10:46 #1
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with a simple query
hi could someone help me with a query.
what i want to do is this,every time a user goes into there control panel 1 is added to a field called visite in the database, what i want is the code for when the visite field in the database reaches 25 it takes them to a order page instead of them going to there control panel.
thanks paul
-
Jul 3, 2007, 10:57 #2
- Join Date
- Mar 2005
- Location
- Ukraine
- Posts
- 1,403
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
On each page load (or every time user logs in) execute the query:
Code sql:UPDATE users SET visite = visite + 1
And add a check (assuming $user is coming from the database):
PHP Code:if ($user['visite'] >= 25) {
header('Location: order.php');
return;
}
-
Jul 3, 2007, 11:27 #3
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi thanks for the fast reply.
i have tried the code but no joy if they have visited 25 0r over it still lets them into the control panel and not the order.php page
here is the full code iam using.
PHP Code:$query = "SELECT id FROM mcgallery_members WHERE login = '$private_login' AND password = '$private_pass'AND level = 'admin'";
$res = mysql_query($query);
$verif = mysql_num_rows($res);
if ($verif == 1)
{
if ($_SESSION['visite'] >= 25) { header('Location: order.php'); return; }
$date = date("Y-m-d H:i:s");
$query="UPDATE mcgallery_members SET visite=visite + 1, date='$date' WHERE login ='$private_login'";
mysql_query($query);
}
-
Jul 3, 2007, 13:50 #4
- Join Date
- Mar 2005
- Location
- Ukraine
- Posts
- 1,403
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do you set $_SESSION['visite']?
-
Jul 4, 2007, 02:35 #5
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi
i have tried
PHP Code:if ($_SESSION['visite'] >= 25) { header('Location: order.php'); return; }
PHP Code:if ($private_login' ['visite'] >= 25) { header('Location: order.php'); return; }
PHP Code:if ($user['visite'] >= 25) { header('Location: order.php'); return; }
-
Jul 4, 2007, 03:27 #6
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
change your first query from this --
SELECT id FROM mcgallery_members WHERE ...
to this --
SELECT id, visite FROM mcgallery_members WHERE ...
then do your 25 test on the value returned
-
Jul 4, 2007, 03:40 #7
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi still lets me go to the control panel and not the order page when they have visited 25 times or over been on this 2 days can't understand why it wont work
-
Jul 4, 2007, 03:52 #8
- Join Date
- Mar 2005
- Location
- Ukraine
- Posts
- 1,403
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can you add this line of code before if statement:
PHP Code:echo '<!-- Session Visite: ' . $_SESSION['visite'] . " -->\n";
-
Jul 4, 2007, 04:07 #9
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If i check the visite field in the database it adds 1 every time i log in no problem
-
Jul 4, 2007, 04:14 #10
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
-
Jul 4, 2007, 04:19 #11
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the problem is when they have loged in 25 times i want it to take them to the order.php page and not the index.php page but it does not work
-
Jul 4, 2007, 04:25 #12
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
did you understand post #6?
-
Jul 4, 2007, 04:31 #13
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi
i put visite in the query but still makes no difference
i thought this would be simple to do but i must have been wrong,because i have been on this problem for 2 days with no joy.
-
Jul 4, 2007, 04:35 #14
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Afternoon Paul,
try
Code PHP:$query = " SELECT id, visite FROM mcgallery_members WHERE login = '$private_login' AND password = '$private_pass' AND level = 'admin'"; $res = mysql_query($query); $verif = mysql_num_rows($res); if ($verif == 1) { $rows = mysql_fetch_assoc($res); if ($rows['visite'] >= 25) { header('Location: order.php'); exit(); } else { $query=" UPDATE mcgallery_members SET visite=visite + 1, date=current_timestamp WHERE login ='$private_login'"; mysql_query($query); } }
Last edited by spikeZ; Jul 4, 2007 at 04:47. Reason: Added Rudy's Timestamp solution
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jul 4, 2007, 04:36 #15
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
in post #3 you showed "the full code"
could you do this again please, to show how you've changed it to test the visite value out of the database?
-
Jul 4, 2007, 04:37 #16
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
never mind, it looks like spike beat you to it
spike, remove this --Code:$date = date("Y-m-d H:i:s");
Code:date='$date'
Code:date=current_timestamp
-
Jul 4, 2007, 04:48 #17
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Rudy - done and notice the nice formatting of the queries.......
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jul 4, 2007, 04:54 #18
- Join Date
- Jan 2005
- Location
- england
- Posts
- 329
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi spikz
tried your code works great thanks spikz you have helped me with php for about a year now.
thankyou for everyones input
i
-
Jul 4, 2007, 05:28 #19
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
no problem Paul, happy to help
Did you get why that code worked an the other didnt?Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
Bookmarks