Jump to content

Recommended Posts

Hi, been awhile since I posted. But I do need your help anyone please. This is driving me up the wall.

 

I have this game I've been creating and working on over the last year in my free time. As well using it to learn php and mysql.

 

So to get to the problem. In my game I have it where players can produce/create weapons and such things of their own. As well they are able to cast spells.

 

So I have this code I took from casting spells and tried to convert it to work for producing weapons but in this case bows... This coding works for casting spells but won't work for production. Even though its all works in the same exact way. So thats my problem. I can't produce bows with my code.

 

Heres the code...

 

On the first page......

Production.php

<form action='../production/bows.php' method='post'>
<select name='spell' length='20'>
<option>Bows</option></select><P><input type=submit name=submit value=Cast></form>

 

On the second page to produce the actual bows.....

bows.php

<?php

if (isset($_SESSION['player'])) 
{
  
$player=$_SESSION['player'];
  
if(isset($_POST['submit']))
{

echo "<center>";
$userstats="SELECT * from ac_users where playername='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);

$spell=$_POST[spell];


$heal=$_GET[heal];
$heal=$_POST[heal];

echo "$heal";

if($userstats3['wood']<1)
{
print "
Not enough wood to produce that.";

}
else
{

if ($spell==bows)
{

if($userstats3[numturns]<1)
{
echo "<center><font color=#FFFFF face=Verdana size=1>You need 1 Turns to produce that.<a href=index.php> Back</a>";
}
else
{
$gain=rand(1,5);

$sql="update ac_users set bows=bows+'$gain', numturns=numturns-1, wood=wood-1 where playername='$player'";
mysql_query($sql) or die("Can't Create Bows");

$totalgold=$gain+$userstats3[bows];

echo "<font color=#FFFFF face=Verdana size=1>You produced $gain bows";

}
}
}
}
}

?>

 

Sorry I know my coding ain't perfect, but like I said I'm learning and was converting this code to at least work. But it won't for some reason. If anyone could help I would surely appreciate it greatly. And thank you very much in advance.

Link to comment
https://forums.phpfreaks.com/topic/74638-solved-help-with-errors-in-code/
Share on other sites

<?php

if (isset($_SESSION['player'])) 
{
  
$player = $_SESSION['player'];
  
if(isset($_POST['submit']))
{

	echo "<center>";
	$userstats = "SELECT * FROM `ac_users` WHERE `playername` = '$player'";
	$userstats2 = mysql_query($userstats) or die(mysql_error());
	$userstats3 = mysql_fetch_array($userstats2);

	$heal = $_POST[heal];

	echo "$heal";

	if($userstats3['wood'] < 1)
	{
		echo "Not enough wood to produce that.";

	} else {

		if ($_POST['spell'] == 'Bows')
		{

			if($userstats3['numturns'] < 1)
			{
				echo "<center><font color=#FFFFF face=Verdana size=1>You need 1 Turns to produce that.<a href=index.php> Back</a>";
			} else {
				$gain = rand(1,5);

				$sql = "UPDATE `ac_users` SET `bows`= bows+'$gain', `numturns` = numturns-1, `wood` = wood-1 WHERE `playername` = '$player'";
				mysql_query($sql) or die("Can't Create Bows");

				$totalgold = $gain + $userstats3['bows'];

				echo "<font color=#FFFFF face=Verdana size=1>You produced $gain bows";

			}
		}
	}
}
}

?>

 

<form action="../production/bows.php" method="post">
<select name="spell" length="20">
	<option>Bows</option>
</select>
<p> <input type="submit" name="submit" value="Cast"> </p>
</form>

 

Don't forget PHP is case sensitive, you had bows instead of Bows in your if statment.

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.