Web Hosting Talk







View Full Version : Script disfuction


Jouninshinobi
02-15-2005, 09:42 AM
Every time I try this script it dosen't come up with an error but it dosen't work either. What happens is the program automaticallly jumps to the else if statement even if the regular if is true.





<body bgcolor="#000000" text="#FFFFFF" link="#666666" vlink="#003399" alink="#0099CC">
<?php
include 'connect.php';
session_start();
?>

<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$userstats="SELECT * from km_users where playername='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);


if(isset($_POST['submit']))
{
$name=$_POST['name'];
$cash="SELECT gold from km_users where playername='$userstats3[playername]'";
$totalcash=($cash);
$wep=$_POST['wep'];
$price="SELECT price FROM price WHERE name='$wep'";
$totalcost=($price);

print "<center>";
print "<table class='maintable'>";
print "<tr class='headline'><td><center>Merchant Shop</center></td></tr>";
print "<tr class='mainrow'><td>";


//I WANT THIS ONE TO REGISTER BUT IT WON'T, I THOUGHT IT MIGHT BE MY SESSIONS


if($totalcost<=$userstats3[gold])
{

//This is a mess but I don't think the problem is here

$increase="SELECT points FROM price WHERE price='$userstats3[gold]'";
$old="SELECT pts FROM km_users WHERE ID='$userstats3[ID]'";
mysql_query($old) or die("no old");
$change="UPDATE km_users SET skillpts=skillpts-'$old' WHERE ID='$userstats3[ID]'";
mysql_query($change) or die("no change");
mysql_query($increase) or die("no increase");
$evo="UPDATE km_users SET skillpnts=skillpnts+'$increase', pts='$increase', WHERE ID='$userstats3[ID]'";
mysql_query($evo) or die("no evo");
$choose="SELECT name FROM price WHERE price='$userstats3[gold]'";
mysql_query($choose) or die("can't choose");
$getwep="UPDATE km_users SET gold=gold-'$userstats3[gold]', weps='$choose', WHERE ID='$userstats3[ID]'";
mysql_query($getwep) or die("Can't get wep");

print "<div align=center><font color=#ffffff size=+3 face=BankGothic Lt BT>Weapon aquired. Go back to <A href='index.php'>Main</a>.</font></div>";
}

////////////////////////////
//IT JUMPS HERE EVERY TIME//
////////////////////////////

else if($totalcost>$userstats3[gold])
{

print "<div align=center><font color=#ffffff size=+3 face=BankGothic Lt BT>You do not have that much gold, go back to the <p><center><A href='index.php'>Main page</center></a></font></div>";
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
}

}

}
?>

probonic
02-15-2005, 10:00 AM
I do believe part of the reason it's not working properly is because $userstats3[gold] should be $userstats3['gold'] I think PHP may be interpreting "gold" as a constant.

And also, it may be worth taking the reference to the array variable out of the quotes and concatenate it into the string instead in your first SQL statement. I have had funny things happen with PHP not recognising what part of a string is a variable name and what isn't.

Jouninshinobi
02-15-2005, 10:34 AM
Should I have changed all the gold or just the if statements?
cause now I have this error

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jounin/public_html/weaponshop.php on line 36

and this line 36

$increase="SELECT points FROM price WHERE price='$userstats3['gold']'";


Note: If change the if statements gold and not the line 36 down it really dosen't change anything. The code still reads you don't have enough money return to the main page.

thartdyke
02-15-2005, 11:37 AM
Change that line to:
$increase="SELECT points FROM price WHERE price='" . $userstats3['gold'] . "'";
You may well have other problems. You session_start() should come before you have output anything. You have a <body> tag being output first.

Jouninshinobi
02-15-2005, 04:19 PM
Still not working, could thier be a problem with this



if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$userstats="SELECT * from km_users where playername='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);



maybe the information for the session isn't getting through??????

thartdyke
02-15-2005, 04:29 PM
"echo" is your friend! Spit out $_SESSION['player'] to see what its value is.

Jouninshinobi
02-15-2005, 04:38 PM
I just tried that, nothin came out

???????????????????????????????????????????


How do I remedy

thartdyke
02-15-2005, 04:41 PM
So you know for sure it's not being set when you think it is. Where do you think it's being set?

Jouninshinobi
02-15-2005, 04:53 PM
I beleive it is set on the index page which uses a form to start the program

I would post but its kinda long...

Do you have an email maybe AIM