Changing database values for the session user on click?

Alright, this has been giving me stress for a very long time, Im making a text-adventure game site and I have already implemented a nice login/register for the site. What im trying to do is make it so when a user completes a “chapter” in the game, they can hit a complete button that will change the chapter INT value to the number of the chapter. Here is what I have so far:

My Members Only PHP page (using for testing purposes):

[code]<?php session_start(); ?>

Advanced Registration & Login Tutorial

Members Area

<?php session_start(); if(isset($_SESSION['username'])) { ?>

	Welcome to members area<br />You are logged in as: <?php echo $_SESSION['username']; ?>
	<br /><a href="logout.php">Logout</a>


Complete Chapter One!

<?php } else { ?>

	Please login to see this page
    
<?php } ?>
[/code]

This is the php file that i was attempting to connect to in the function:

[php]$con = mysql_connect(log in info);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“db_name”, $con);

$sql=“UPDATE users SET chapter = 1 WHERE username=’”.$_SESSION[‘username’]."’";

mysql_query($sql);[/php]

Im not getting any errors, but when the button is clicked to change the value, nothing happens in the database… what am I doing wrong?!

You’re not providing much code here but… if your second block of code is a different file, did you make sure to add session_start() ?

Sponsor our Newsletter | Privacy Policy | Terms of Service