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

Recommended Answers

All 9 Replies

Member Avatar for LastMitch

@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.

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?

Member Avatar for LastMitch

@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!

Member Avatar for Zagga

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.

@LastMitch

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

@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.

Member Avatar for LastMitch

@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

commented: To Rectify what some retard did to LastMitch +0
Member Avatar for Zagga

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());
?>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.