SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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

  2. #2
    An average geek earl-grey's Avatar
    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;


  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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);


  4. #4
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you set $_SESSION['visite']?

  5. #5
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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('Locationorder.php');   return; } 
    PHP Code:
    if ($user['visite'] >= 25) {   header('Location: order.php');   return; } 
    but nothing seems to work

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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

  8. #8
    An average geek earl-grey's Avatar
    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"
    Login to the contol panel several times, view source of the generated page and check what is visite value and whether it increases.

  9. #9
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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

  10. #10
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by pwesthead View Post
    If i check the visite field in the database it adds 1 every time i log in no problem
    so your problem is ... ?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  11. #11
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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

  12. #12
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    did you understand post #6?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  13. #13
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    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.

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    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.....

  15. #15
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  16. #16
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    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");
    and change this--
    Code:
    date='$date'
    to this--
    Code:
    date=current_timestamp
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    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.....

  18. #18
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    england
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    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

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •