1

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
13
Views
5 Years
Discussion Span
Last Post by Yorkiebar14
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.

0

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?

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!

Edited by LastMitch: grammer

0

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.

0

@LastMitch

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

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.

3

@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

Edited by LastMitch: grammer

Votes + Comments
To Rectify what some retard did to LastMitch
3

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());
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.