Jump to content

[SOLVED] Get field using userID session


SirChick

Recommended Posts

i have this script:

 

$GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'";

$EXP = $GetEXP["CrimeExp"];

Echo $EXP;

 

but its not echoing it correctly it should display the crimeexp for the user but its not working ... what have i got wrong?

Link to comment
Share on other sites

you need to run that query

 

<?php
$GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'";
$result = mysql_query($GetEXP) or die(mysql_error());  
$EXP = mysql_result($result,0,"CrimeExp");
Echo $EXP;
?>

however if you need more data than exp try getting it all in 1 query instead of taking 1 piece of data at a time.

Link to comment
Share on other sites

still doesn't echo it :S

this is what i have:

 

<?
//include connect info
include("include.php");
// Start up the session
session_start();
if (!isset($_SESSION['Current_User']) || !$_SESSION['Current_User']) {
die('You must be logged in to view this page');
}


//getting exp from database	
$GetEXP = "SELECT userregistration GET CrimeExp WHERE UserID='{$_SESSION['Current_User']}'";
$result = mysql_query($GetEXP) or die(mysql_error());  
$EXP = mysql_result($result,0,"CrimeExp");
Echo $EXP;
?>

Link to comment
Share on other sites

<?
//include connect info
include("include.php");
// Start up the session
session_start();
if (!isset($_SESSION['Current_User']) || !$_SESSION['Current_User']) {



die('You must be logged in to view this page');
}


//getting exp from database
$GetEXP = "SELECT CrimeExp  FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'";
$result = mysql_query($GetEXP) or die(mysql_error());  
$EXP = mysql_result($result,0,"CrimeExp");
echo $EXP;
?>

Link to comment
Share on other sites

try

<?php
//getting exp from database
$GetEXP = "SELECT CrimeExp  FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'";
echo $GetEXP;
$result = mysql_query($GetEXP) or die(mysql_error());  
$EXP = mysql_result($result,0,"CrimeExp");
echo $EXP;
?>

 

what is echo'd

Link to comment
Share on other sites

ok ill give u all the code cos theres includes involved here, this first script decides if it will load success or failure using a rand feature.

 

This is UnderBridgeCrimeScript.php

<?
//include loads session and connects to database
include("include.php");


// Get the user's info from the database by putting
// the user id stored in the session into the WHERE clause
$GetUserID = mysql_query("SELECT * FROM userregistration
                    WHERE UserID='{$_SESSION['Current_User']}'");
                  
// Fetch the row from the database
if (!($row = mysql_fetch_assoc($GetUserID))) {
    echo "User not found!";
    exit;
}
//assigns user's crimeexp to this field  
$EXP = $row["CrimeExp"];

//rand is created to choose at random if they succeed or fail..
if ($EXP <= 100) {
    $rand = rand(1,5);
    if ($rand < 3) {
        include('bridgefailure.php');
    } else {
        include('bridgesuccess.php ');
    }
}
?>

 

 

then success has this script which makes a variable named $QuoteResult which i will show you how it is used further on:

 

This is bridgesuccess.php

<?
include("include.php");


//FIRST RAND
$rand = rand(1,5);
if ($rand == 1) {
				$QuoteResult = "Result: You search the train station from top to bottom and find $1!";}

// update the user's money to 1 more than what it was
$addMoney = "UPDATE userregistration SET MoneyInHand=MoneyInHand+1 WHERE UserID='{$_SESSION['Current_User']}'";
$firstrandresult = mysql_query($addMoney) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
die('Error ID 0001 contact admin on the Civilian forums immediately about this error!');
}
// update the user's crimeexp to 2 more than what it was
$addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp+2 WHERE UserID='{$_SESSION['Current_User']}'";
$expresult = mysql_query($addcrimeexp) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
  die('Error ID 0001, contact admin on the Civilian forums immediately about this error!');
}

?>

 

OR the script loads failure (as the user may succeed or fail the crime) This also makes the quote for the result but will be a different string for the variable:

 

This is bridgefailure.php

<?
//includes session and connect
include("include.php");





//FAIL RESULT
$QuoteResult = "You failed to find any money, better try some other time!";








// update the user's crimeexp to 1 less than what it was
$addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp-1 WHERE UserID='{$_SESSION['Current_User']}'";
$expresult = mysql_query($addcrimeexp) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
  die('Error ID 0002, contact admin on the Civilian forums immediatly about this error!');
}
?>

 

 

 

Once this is done on the main page, which the user can view, it displays the $QuoteResult, but infact it doesn't display anything, other than the last echo in the if statement below this paragraph which suggests the $QuoteResult is null and thats why i thought it was to do with the script i showed at the start of this thread. But i have suspicious feeling that its something else.

 

This is the UnderTheBridge.php - this starts off the above scripts from a user pressing the 'DoCrime' button.

<? 
if (isset($DoCrime['DoCrime'])){
include("UnderBridgeCrimeScript.php");
}
?>

 

 

 

And below that in the same .php file however

<div id="bv_" style="position:absolute;left:307px;top:348px;width:262px;height:64px;z-index:14" align="center">
<?
echo $$QuoteResult;
if($QuoteResult == 'Result: You search the train station from top to bottom and find $1!')
{
echo '<font style="font-size:16px" color="green" face="Arial">';
echo $QuoteResult;
echo '</font></div>';
}else if($QuoteResult == 'You failed to find any money, better try some other time!')
{
echo '<font style="font-size:16px" color="red" face="Arial">';
echo $QuoteResult;
echo '</font></div>';
}else if($QuoteResult == 'Result: You search the train station from top to bottom and find $3!')
{
echo '<font style="font-size:16px" color="green" face="Arial">';
echo $QuoteResult;
echo '</font></div>';
}else if($QuoteResult == 'Result: You search the train station from top to bottom and find $5!')
{
echo '<font style="font-size:16px" color="green" face="Arial">';
echo $QuoteResult;
echo '</font></div>';
}else
{
echo '<font style="font-size:16px" color="red" face="Arial">';
echo 'Server is having difficulties admin is working on it!';
echo '</font></div>';
}
?>

 

 

 

its this last bit of code that is the problem it wont echo the $QuoteResult...

Link to comment
Share on other sites

revised bridgesuccess.php

 

<?php
<?
include("include.php");



//FIRST RAND
$rand = rand(1,5);
if ($rand == 1)
{
$QuoteResult = "Result: You search the train station from top to bottom and find $1!";
}else{
$QuoteResult = "Result: You search the train station from top to bottom and find NOTHING!";
}

// update the user's money to 1 more than what it was
$addMoney = "UPDATE userregistration SET MoneyInHand=MoneyInHand+1 WHERE UserID='{$_SESSION['Current_User']}'";
$firstrandresult = mysql_query($addMoney) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
die('Error ID 0001 contact admin on the Civilian forums immediately about this error!');
}
// update the user's crimeexp to 2 more than what it was
$addcrimeexp = "UPDATE userregistration SET CrimeExp=CrimeExp+2 WHERE UserID='{$_SESSION['Current_User']}'";
$expresult = mysql_query($addcrimeexp) or die(mysql_error());
if (mysql_affected_rows() == 0)
{
die('Error ID 0001, contact admin on the Civilian forums immediately about this error!');
}
?>

Link to comment
Share on other sites

cant have:

 

}else{

$QuoteResult = "Result: You search the train station from top to bottom and find NOTHING!";

}

 

 

because failure is on a different php file . it has to be for future reasons to do with other features..thats why i kept them seperate to avoid it getting messy.

Link to comment
Share on other sites

OK.. if you say so but the logic says

 

$rand = rand(1,5);
if ($rand == 1)

so $QuoteResult will only be set 20% of the time..

 

so have

//FIRST RAND
$rand = rand(1,5);
if ($rand == 1)
{
$QuoteResult = "Result: You search the train station from top to bottom and find $1!";
}else{
$QuoteResult = "Result: You search the train station from top to bottom and find NOTHING!";
}

 

or

 

//FIRST RAND
$QuoteResult = "Result: You search the train station from top to bottom and find $1!";

 

but hey you know best!

Link to comment
Share on other sites

yeh i got 5 rands in total but i only shown you the first the rest are all the same structure. didnt think you would need to know all the rands.

 

cos its like this:

 

//rand 1 
if == 1 
then its this result: $Resultquote = "success1";

//rand 2
if == 2 
then its this result: $Resultquote = "success2";

 

 

its too long to show you all the rands so i shown you the first one so u can see what was going on. But i duno why it wont pass the info of $QuoteResult to the the other scripts

Link to comment
Share on other sites

read the logic

 

UnderBridgeCrimeScript.php

//rand is created to choose at random if they succeed or fail..

if ($EXP <= 100) {
    $rand = rand(1,5);
    if ($rand < 3) {
        include('bridgefailure.php');
    } else {
        include('bridgesuccess.php '); //Gets here
    }
}

 

$QuoteResult hasn't been set yet

 

'bridgesuccess.php '

//FIRST RAND
$rand = rand(1,5); //Random from 1 to 5
if ($rand == 1) { //if its 5 then set $QuoteResult
$QuoteResult = "Result: You search the train station from top to bottom and find $1!";
}

//if not 1 then $QuoteResult is still not set..

 

 

its this last bit of code that is the problem it wont echo the $QuoteResult...

 

EDIT:

 

also change

echo $$QuoteResult;

to

echo $QuoteResult;

Link to comment
Share on other sites

ok i get you now would it work doing something along the lines of :

 

$rand = rand(1,5); //Random from 1 to 5
if ($rand == 1) { //if its 5 then set $QuoteResult
$QuoteResult = "Result: You search the train station from top to bottom and find $1!";
elseif ($rand == 2)
$QuoteResult = "Result: You search the train station from top to bottom and find $5!";
}
etc..

 

untill all rand choices would effectively set the result..?

Link to comment
Share on other sites

try this

<?php
$Wins[] = "Result: You search the train station from top to bottom and find $1!";
$Wins[] = "Result: You search the train station from top to bottom and find $3!";
$Wins[] = "Result: You search the train station from top to bottom and find $5!";
$Wins[] = "Result: You search the train station from top to bottom and find $10!";
$Wins[] = "Result: You search the train station from top to bottom and find $15!";


$rand = rand(0,(count($Wins)-1)); 
$QuoteResult = $Wins[$rand];

echo $QuoteResult; //remove this (was for testing)
?>

 

 

EDIT: note if you add an extra

 

$Wins[] = "Result: You search the train station from top to bottom and find $15!";

 

it will work with it

 

note i updated the above code

Link to comment
Share on other sites

not in that version (i created 2 scipts that worked better and didn't need the number but i forgot to remove them)

 

if you add more lines to they will be included

 

ie

$Wins[] = "Result: You search the train station from top to bottom and find $1!";
$Wins[] = "Result: You search the train station from top to bottom and find $3!";
$Wins[] = "Result: You search the train station from top to bottom and find $5!";
$Wins[] = "Result: You search the train station from top to bottom and find $10!";
$Wins[] = "Result: You search the train station from top to bottom and find $15!";
$Wins[] = "Result: You search the train station from top to bottom and find $20!";
$Wins[] = "Result: You search the train station from top to bottom and find $30!";
$Wins[] = "Result: You search the train station from top to bottom and find $50!";
$Wins[] = "Result: You search the train station from top to bottom and find $100!";
$Wins[] = "Result: You search the train station from top to bottom and find $150!";

 

so updates are easier.. with games you need to think about making updates easy!!

 

players are demanding people!!!!

Link to comment
Share on other sites

hang on lol

 

the result seems to always be :

 

Result: You search the train station from top to bottom and find $10!

 

 

//RAND
$Wins[] = "Result: You search the train station from top to bottom and find $1!";
$Wins[] = "Result: You search the train station from top to bottom and find $3!";
$Wins[] = "Result: You search the train station from top to bottom and find $5!";
$Wins[] = "Result: You search the train station from top to bottom and find $8!";
$Wins[] = "Result: You search the train station from top to bottom and find $10!";


$rand = rand(0,(count($Wins)-1)); 
$QuoteResult = $Wins[$rand];

Link to comment
Share on other sites

test script

 

create a new file paste this in

<?php
$Wins[] = "Result: You search the train station from top to bottom and find $1!";
$Wins[] = "Result: You search the train station from top to bottom and find $3!";
$Wins[] = "Result: You search the train station from top to bottom and find $5!";
$Wins[] = "Result: You search the train station from top to bottom and find $10!";
$Wins[] = "Result: You search the train station from top to bottom and find $15!";


$rand = rand(0,(count($Wins)-1)); 
$QuoteResult = $Wins[$rand];

echo $QuoteResult;
?>

 

run it a few times i got

 

$10

$10

$3

$5

$1

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.

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.

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