Jump to content

Need some help with PHP and MySQL session variables


Stalingrad
 Share

Recommended Posts

Hi All! I've written up a script for my website. It\ is basically a virtual job quest. My queries are all correct it just isn't registering the variable for the session. It is $-SESSION[theid']. I want to be bale to use it in my table but I get an error. How do I write this in my SQL query for it to work. The page (when no errors), doesn't show my data. Here is my ocde:

 

<?php
session_start();
include("config536.php");
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<?php
if(!isset($_SESSION['username'])) {
echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Messages</font><br><br></center></content>";
}

if(isset($_SESSION['username'])) {
echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Basic Quests</font><br><br>";

$startjob = $_POST['submit'];
$jobq = "SELECT * FROM jobs WHERE username='$showusername'";
$job = mysql_query($jobq);
$jobnr = mysql_num_rows($job);

if($jobnr == "0") {
?>
<form action="<?php echo "$PHP_SELF"; ?>" method="POST">
<input type="submit" name="submit" value="Start Job"></form>
<?php
}
if(isset($startjob)) {
$initemidq = "SELECT * FROM items ORDER BY RAND() LIMIT 1";
$initemid = mysql_query($initemidq);
while($ir = mysql_fetch_array($initemid)) {
$ids = $ir['itemid'];
}
mysql_query("INSERT INTO jobs (username, item, time, completed) VALUES ('$showusername', '$ids', 'None', 'No')");
$wegq = "SELECT * FROM items WHERE itemid='$ids'";
$weg = mysql_query($wegq);
while($wg = mysql_fetch_array($weg)) {
$im = $wg['image'];
$nm = $wg['name'];
$id = $wg['itemid'];
}
$_SESSION['theid'] = $id;

echo "<font color=green>Success! You have started this Job!</font><br><br>Please bring me this item: <b>$nm</b><br><br><img src=/images/items/$im><br><br><br>";
echo $_SESSION['theid'];
}

if($jobnr == "1") {
$finish = $_POST['finish'];
$okgq = "SELECT * FROM items WHERE itemid='$yes'";
$ok = mysql_query($okgq);
while($ya = mysql_fetch_array($ok)) {
$okname = $ya['name'];
$okid = $ya['itemid'];
$okimage = $ya['image'];
}
echo "Where is my <b>$okname</b>?<br><br><img src=/images/items/$okimage><br><br><br>";
echo $_SESSION['theid'];
?>
<form action="<?php echo "$PHP_SELF"; ?>" method="POST">
<input type="submit" name="finish" value="I have the Item"></form>
<?php
}
}

if(isset($finish)) {
$cinq = "SELECT * FROM uitems WHERE theitemid='$_SESSION[theid]'";
$cin = mysql_query($cinq);
$connr = mysql_num_rows($cin);
if($connr != "0") {
echo "<font color=green>Success! You have the item.</font>";
} else {
echo "<font color=red>Error! You do not have my item!</font>";
}

}
?>

. I basically just want to know how I can set this session as a variable. Also..I have a user login on every page and I want to be able to destroy JUST THE "theid" session and NOT the username session. How would I do that too? thanks for the help in advance!

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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

 Share

×
×
  • 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.