We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,466 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Need a script to unlock certain pages after completion

Hello,

I am making a website to do with different tests so I need a script which can unlock test 2 after test 1 is completed. Then the same for 3, then 4 etc etc.

I tried using MySQL to increase an INT so I could tell what the latest test a user completed was but I could not make the int increase so I don't know what to try.

Any help would be great.
Thanks

3
Contributors
9
Replies
23 Hours
Discussion Span
7 Months Ago
Last Updated
10
Views
Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@Yorkiebar14

Need a script to unlock certain pages after completion

Can you elaborate more? It's very hard to understand what you need help with without any code.

LastMitch
Industrious Poster
4,195 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45

I have 4 tests. Each user must complete test 1 in order to progress to test 2. They must then complete test 3 then 4. How can I make it so they can't access certain tests without completeing the previous one first?

Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@Yorkiebar14

May I ask what was the downvote for? The answer was to provide a code~! Without any code it will be difficult plus noone will write it for you!

LastMitch
Industrious Poster
4,195 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45

Hi Yorkiebar14,

Your idea of increasing a database INT is a good one.
As soon as your user has completed each test, connect to your database, select a database table, then update the variable.

Zagga
Posting Whiz
372 posts since Dec 2009
Reputation Points: 45
Solved Threads: 78
Skill Endorsements: 4

@LastMitch

Just to clarify, I didn't downvote you... Just incase I did by accident I just upvoted you :)

Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@Zagga

Thanks, could you help me with it though? I wrote the code perfectly but it would not increase the int.

The code I wrote is;

//Connects to mysql
//Selects DB

        $query = "select * from users where user='{$_SESSION['username']}'";
        $result = mysql_query($query) or die(mysql_error());
        $getinfo = mysql_fetch_row($result); 
        $basicLevel = $getinfo[3];
            mysql_query("UPDATE users SET BasicLevel = BasicLevel +1 where username='Admin'");

And before you say it, yes all the field names are correct and BasicLevel is an INT in my database.

Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@Yorkiebar14

Just to clarify, I didn't downvote you... Just incase I did by accident I just upvoted you :)

I wasn't too sure why someone downvote comment when I wasn't being rude or offended anyone it was just asking for a code. But Thanks.

OK, You said the query is working

$query = "select * from users where user='{$_SESSION['username']}'";
$result = mysql_query($query) or die(mysql_error());
$getinfo = mysql_fetch_row($result);
$basicLevel = $getinfo[3];
mysql_query("UPDATE users SET BasicLevel = BasicLevel +1 where username='Admin'")

Try to put $id in here

$query = "select * from users where user='{$id = $_SESSION['username']}'";

Try to do this in the query in PHPMyAdmin:

CREATE PROCEDURE increment (IN uniqid VARCHAR(255))
BEGIN
   UPDATE `users` SET BasicLevel = BasicLevel + 1 WHERE id = uniqid;
   SELECT BasicLevel FROM `users` WHERE id = uniqid;
END

Let me know did it increase the INT

LastMitch
Industrious Poster
4,195 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45

Hi again,

Sorry to jump in here LastMitch, but this may be a concetanation error with the initial query $query = "select * from users where user='{$_SESSION['username']}'";

If I were you, I would set a variable for $_SESSION['username'], and increment $basicLevel outside of the queries.

<?php
//Connect to mysql
//Select DB



$username = $_SESSION['username'];

// Get current BasicLevel value.
$query = "SELECT BasicLevel FROM users WHERE user='" . $username . "'";
$result = mysql_query($query) or die(mysql_error());

// Set and increment BasicLevel value.
$basicLevel = $result[3];
$basicLevel += 1;

// Store new BasicLevel value.
$update_query = "UPDATE users SET BasicLevel='" . $basicLevel . "' WHERE username='" . $username . "'";
$update_result = mysql_query($update_query) or die(mysql_error());
?>
Zagga
Posting Whiz
372 posts since Dec 2009
Reputation Points: 45
Solved Threads: 78
Skill Endorsements: 4

Big thanks to both of you, its working now! :D

Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0863 seconds using 2.7MB