Page 1 of 1

Posting help

Posted: Fri Sep 02, 2005 12:30 pm
by Raven-flock
Im working on a small fighting game and ran into a problem now i need help on making it work right i need to make it where it will update the armor, gold and defense fields in the database now on the gold i need it to take away how much the armor cost. and i need it to make the armor name put in there and then make the defense on how much the armor has on its defense.. can someone help me now here is the armor shop and the armor shop 2 pages and i want it where when they buy something it will go back to the armor shop page and say like You are the Proud owner of {armor}..

(armorpage.php should be fine its armorpage2 thats the problem)
Armorpage.php

Code: Select all

<center>
<?php
include 'db.php';

$sql = mysql_query("SELECT * FROM users WHERE user_name = '".$_SESSION['user_name']."'");
	while ($row = mysql_fetch_array($sql)) {

if (($_SESSION['user_level'] == 1) || ($_SESSION['user_level'] == 2) || ($_SESSION['user_level'] == 3)  || ($_SESSION['user_level'] == 4)  || ($_SESSION['user_level'] == 5)) {

echo '<font class="txt">You have Gold: '. $row["gold"] .' and Money '. $row["money"] .'</font>';

}
}
?>
<?php
include 'db.php';

$sql = mysql_query("SELECT * FROM users WHERE user_name = '".$_SESSION['user_name']."'");
	while ($row = mysql_fetch_array($sql)) {
?>
<br><br>
<font class="txt">
<form name="armor" method="post" action="armorshop2.php">
<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><?php
include 'db.php';
$gold = $row['gold'];
if ($gold >= 50) {
echo'<input name="armor" type="radio" value="shield">';
}else{
     echo '&nbsp;';
}
?></td>
<td>Shield</td>
<td>0/5</td>
<td>5 gold</td>
</tr>
<tr>
<td><?php
include 'db.php';
$gold = $row['gold'];
if ($gold >= 100) {
echo '<input name="armor" type="radio" value="leatherhelmet">';
}else{
     echo'&nbsp;';
}
?></td>
<td>Leather Helmet</td>
<td>0/5</td>
<td>10 gold</td>
</tr>
<tr>
<td><?php
include 'db.php';
$gold = $row['gold'];
if ($gold >= 100) {
echo '<input name="armor" type="radio" value="bodyguard">';
}else{
     echo'&nbsp;';
}
?></td>
<td>Body Guard</td>
<td>0/10</td>
<td>25 gold</td>
</tr>
<tr>
<td><?php
include 'db.php';
$gold = $row['gold'];
if ($gold >= 100) {
echo '<input name="armor" type="radio" value="steelarmor">';
}else{
     echo'&nbsp;';
}
?></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>
<?php
}
?>
Armorpage2.php

Code: Select all

<?php
include 'db.php';

$armor = $_POST['armor'];
$total = $gold - $_POST['gold'];

$sql = mysql_query("UPDATE users ($armor, $total)
		VALUES('armor, total')") 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
Raven-floft

Re: Posting help

Posted: Fri Sep 02, 2005 12:36 pm
by nielsene
Armorpage2.php

Code: Select all

$sql = mysql_query("UPDATE users (armor, total)
		VALUES('$armor', '$total')") or die (mysql_error());
?>
Note, that I chanced armor to $armor, likewise for total and wrapped each in their own quotes, not a single set of quotes surrounding both. as well as flipping the field specifications and field values portions.

I wouldn't suggest passing the cost by Post (or Get), but I beleive people commented on that already in an earlier post.