php - Level & Exp Point System


I'm trying to create a level system, where users gain exp through certain actions and when they have enough, they level up! I've created this levelsystem.php file and included it in header.php so its on every page but it doesn't seem to be working.

$res = mysql_query("SELECT `level`, `exppoints` FROM `users` WHERE `id` = '".$_SESSION['uid']."'");
$data = mysql_fetch_assoc($res);

$level = $data['level'];
$exp = $data['exppoints'];
$expneed = 100;
$levelup = $level * $expneed;

if($exp == $levelup) {
$res2 = mysql_query("UPDATE `users` SET `level` = level+1, `exppoints` = exppoints-'".$levelup."' WHERE `id` = '"$_SESSION['uid']."'");

It shows an error for an unexpected variable which I'm assuming is the $levelup in the query, but can't see a way around it.




You are missing the dot concatenation operator on your where statement:

... ."' WHERE `id` = '"$_SESSION['uid']."'"

Should be:

... ."' WHERE `id` = '".$_SESSION['uid']."'"

Adding some spacing around your operators may help improve your code's readability.

Also, themysql_* functions are deprecated as of PHP v5.5. Please try to use MySQLi or PDO instead.




It looks like you are missing a period

this$res2 = mysql_query("UPDATEusersSETlevel= level+1,exppoints= exppoints-'".$levelup."' WHEREid= '"$_SESSION['uid']."'");

$res2 = mysql_query("UPDATEusers SETlevel = level+1,exppoints = exppoints-'".$levelup."' WHEREid = '".$_SESSION['uid']."'");

People are also looking for solutions to the problem: php - Warning: array_merge(): Argument #1 is not an array, when processing two $_POST


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.