Page 1 of 1

Game Script help

Posted: Tue Aug 30, 2005 9:42 pm
by Smackie
Im making a game and well i came across a few problems all in one :? i want to make it where it will check to see if the user has enough gold or money to buy the armor or if i can make it where the radio button will only show when thet user has the same or more money or gold. then make it where it changes the armor, attack, and defense in database. here is my script

armorshop.php

Code: Select all

<?php

echo'
<center>
<font class="txt">
Armor Shop<br>';
require 'inhandgold.php';
echo'
<br><br>
<font class="txt">
<form name="armor" method="post" action="../index.php?pages=armorshop2">
<table width="317" border="1" cellpadding="0" cellspacing="0" class="txt">
<tr>
<td width="21"></td>
<td width="123">Armor Name</td>
<td width="60">Att/Def</td>
<td width="113">Cost</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="sheild"></td>
<td>Sheild</td>
<td>0/5</td>
<td>5 gold</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="leatherhelmet"></td>
<td>Leather Helmet</td>
<td>0/5</td>
<td>10 gold</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="bodyguard"></td>
<td>Body Guard</td>
<td>0/10</td>
<td>25 gold</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="steelarmor"></td>
<td>Steel Armor</td>
<td>0/25</td>
<td>50 gold</td>
</tr>
</table>
<table width="317" border="1" cellpadding="0" cellspacing="0" class="txt">
<tr>
<td><center><input name="armor" type="submit" value="Buy Armor" class="submit-button"></center></td>
</tr>
</form>
</font>
</center>';
?>
armorshop2.php

Code: Select all

<?php
require 'db.php';
$shield = $_POST['shield'];
$leatherhelmet = $_POST['leatherhelmet'];
$bodyguard = $_POST['bodyguard'];
$steelarmor = $_POST['steelarmor'];
$gold = $_GET['gold'];

if (($shield) > ($gold)) {
 
	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if (($letherhelmet) > ($gold)) {

	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if (($bodyguard) > ($gold)) {     

	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if  ((steelarmor) > ($gold)) {

	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if ((!$shield) || (!$leatherhelmet) || (!$bodyguard) || (!$steelarmor)) {

	
	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry you dont have enough gold for this armor</font></center><br>';
	require 'armorshop.php';
	return;
}

$sql = mysql_query("INSERT INTO users (armor)
		VALUES('$armor')") or die (mysql_error());


if (!$sql) {
	
	echo '<center><font class="h">There has been an error adding your armor. Please contact the webmaster.</font></center>';

}

?>
Thank you
Smackie

Posted: Tue Aug 30, 2005 10:37 pm
by feyd
I'm not seeing where your problem is. :?

Posted: Tue Aug 30, 2005 10:40 pm
by Smackie
well it just keeps sending back that i dont got enough gold for the armor and it doesnt update the armor and the defense (not on there still working on that part) or the attack (not on there still working on that part) and well im not sure on them parts and im not sure on how to make it subtrack how much the armor cost either i mean i know how but im not sure on making it more then one thing and changing the price and stuff

Posted: Wed Aug 31, 2005 6:50 am
by raghavan20

Code: Select all

$shield = $_POST['shield']; 
$leatherhelmet = $_POST['leatherhelmet']; 
$bodyguard = $_POST['bodyguard']; 
$steelarmor = $_POST['steelarmor']; 
$gold = $_GET['gold'];
where do you get these POST and GET values from???
I dont know why you have used GET for gold while others have POST.

Posted: Wed Aug 31, 2005 8:00 am
by feyd
shouldn't have gold passed in through the user anyways. ;)

Posted: Wed Aug 31, 2005 8:35 am
by Smackie
the POST ones are to get the infomation from armorshop.php

and the GET is to get the Gold from the database to check to see how much the user has so it can check to see if they have enough to use to buy the armor and so it can get subtracted...

Posted: Wed Aug 31, 2005 10:24 am
by raghavan20
Smackie wrote:the POST ones are to get the infomation from armorshop.php

and the GET is to get the Gold from the database to check to see how much the user has so it can check to see if they have enough to use to buy the armor and so it can get subtracted...
its fine about the post ones.
where do you get the gold value from the db???why do you use a GET? I dont see any url variables being used 8O

Posted: Wed Aug 31, 2005 10:29 am
by Smackie
im getting the gold from users database but i just put that script together im looking for someone that can help me to design it better and make everything work like its suppose to and stuff.. I havent really put a game together so thats why im asking for some help right now :?

Posted: Wed Aug 31, 2005 10:49 am
by thomas777neo
you also spelt shield incorrectly in the armorshop.php

edit: Realised that is your problem if you look @ this piece of code:

Code: Select all

if ((!$shield) || (!$leatherhelmet) || (!$bodyguard) || (!$steelarmor)) { 

     
    echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry you dont have enough gold for this armor</font></center><br>'; 
    require 'armorshop.php'; 
    return; 
}

Posted: Wed Aug 31, 2005 10:59 am
by Smackie
thomas777neo wrote:you also spelt shield incorrectly in the armorshop.php

edit: Realised that is your problem if you look @ this piece of code:

Code: Select all

if ((!$shield) || (!$leatherhelmet) || (!$bodyguard) || (!$steelarmor)) { 

     
    echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry you dont have enough gold for this armor</font></center><br>'; 
    require 'armorshop.php'; 
    return; 
}
i already fixed the spelling before you said anything... and also i dont really see a problem there :? unless you mean with the ! (!$shield)

Posted: Wed Aug 31, 2005 12:29 pm
by Smackie
Can someone help me and change this scirpt so it will work like i want it to?