Jump to content

Capturing Values From Database


Recommended Posts

MySQL Version: 5.0.91


Hi, I am currently working on a Leveling system for users for my website. I'm creating an exp.php file that will contain how much exp is required for the next level up.


I am currently attempting to capture the user's Level which is stored inside the database. However, it isn't being set to my variable. I try echoing it out to see the output, but it comes up blank. Both Exp and Level come up blank. I'm obviously doing the query wrong, otherwise it would be showing.


The purpose of this file is to check what level the current user is (using sessions). Once it gets its level, there will be multiple if statements to determine how much more experience is required to level up. Once the experience is gained, the new level of the user will be increased by one.


A good part of this script is pseudocode (I'm currently not testing those sections).


// This include redirects users to home page if they are not an admin
// Connect to database

$userid = $_SESSION['userid'];

// Temporary Pseudocode, Ignore this for now.
$exptolvl = 100;
$level = 2;	
// Temporary Pseudocode, Ignore this for now.
if (surfed){
$usersexp += 100;

// Query begins.
$expquery = mysql_query("SELECT * FROM users WHERE exp='$exp' AND level='$newlevel'");
$row = mysql_num_rows($expquery);

while($row = mysql_fetch_assoc($expquery))
    $exp = $row['exp'];
    $level = $row['level'];

echo $exp;
echo $level;

$inputexp = mysql_query("UPDATE users SET exp='$exp' and level='$newlevel' WHERE id='$userid'");



And my table called "users" looks like:

id  	int(11)   	No   	    	 
username 	varchar(25) 	No  	  	 
level 	int(2) 	No  	1  	 
email 	varchar(64) 	No  	  	 
fname 	varchar(25) 	No  	  	 
lname 	varchar(25) 	No  	  	 
member 	tinyint(1) 	No  	  	 
referrer 	varchar(25) 	No  	  	 
joindate 	date 	No  	  	 
lastsurfed 	date 	No  	  	 
credits 	decimal(9,3) 	No  	  	 
exp 	int(6) 	No  	  	 
password 	varchar(32) 	No  	  	 
ip 	varchar(15) 	No  	  	 


I get no errors. It just isn't capturing the values correctly.

Link to comment
Share on other sites

Your MySQL conditon doesn't make any sense.

$expquery = mysql_query("SELECT * FROM users WHERE exp='$exp' AND level='$newlevel'");


Since $exp and $newlevel aren't set to anything, the query will return the rows that have exp='' and level=''


I think you want this:


$expquery = mysql_query("SELECT * FROM users WHERE id='{$userid}'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.