question abou attack
-
claymore88
- Posts: 10
- Joined: Tue Aug 16, 2011 8:27 pm
question abou attack
Im new. Went through the videos. Read user posts and came across thorians post about selecting monsters through a drop down menu. But after I made the code how do I fight the creatures submitted/selected it just shows the random monster in that location when I make a submit form to attack.php
I want to b able to select the creature and be able to fight that creature through submission
I want to b able to select the creature and be able to fight that creature through submission
Re: question abou attack
You need to do something like this:
<form method = 'post' action = 'attack.php'>
<option>ghost</option>
<option>goblin</option>
<br />
<input type = 'submit' value = 'Submit!' name = 'creature'>
THEN, on attack.php (Assuming you want to select the creature in battle.php and then fight it in attack.php) get the creature like this:
$creature = $_POST['creature'];
And that should get you the creature that was selected.
Now don't copy and paste the first part with the form, because that was pretty much pseudo code, but it needs to be something like that
Then when defining $creatureinfo, instead of something like "SELECT * FROM creatures WHERE level = '$playerinfo3[level]'";
Do this: "SELECT * FROM creatures WHERE name = '$creature'"; //this will send the creature that was selected from the dropdown menu into the query, and it will select all of the information from that selected creature
Hoped this helped!
<form method = 'post' action = 'attack.php'>
<option>ghost</option>
<option>goblin</option>
<br />
<input type = 'submit' value = 'Submit!' name = 'creature'>
THEN, on attack.php (Assuming you want to select the creature in battle.php and then fight it in attack.php) get the creature like this:
$creature = $_POST['creature'];
And that should get you the creature that was selected.
Now don't copy and paste the first part with the form, because that was pretty much pseudo code, but it needs to be something like that
Then when defining $creatureinfo, instead of something like "SELECT * FROM creatures WHERE level = '$playerinfo3[level]'";
Do this: "SELECT * FROM creatures WHERE name = '$creature'"; //this will send the creature that was selected from the dropdown menu into the query, and it will select all of the information from that selected creature
Hoped this helped!
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
-
claymore88
- Posts: 10
- Joined: Tue Aug 16, 2011 8:27 pm
Re: question abou attack
I still get nothing. is there a similar open source script with this feature? I learn best by actually seeing it
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: question abou attack
You forgot the <select> tag, #dude! (Ahh, just saw you meant it as psuedo code)
I also demonstrate how you can set "values" in each option tag. That way you can use multiple words, or give more description in each option's text, but you will be using the value to actually check what was chosen in the form's action script.
Code: Select all
<form action="process.php" method="post">
<select id="monster" name="monster">
<option value="sandbug">A Giant Sand Beetle</option>
<option value="mummy">An Ancient Mummy</option>
</select>
<input type="submit" value="Submit" />
</form>The indelible lord of tl;dr
-
claymore88
- Posts: 10
- Joined: Tue Aug 16, 2011 8:27 pm
Re: question abou attack
jack, I see what you mean. but if I list all the creatures with one command how do I give them a different name
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: question abou attack
What do you mean list all the creatures in one command? That is not what I was suggesting.
The indelible lord of tl;dr
Re: question abou attack
Code: Select all
$creature = $_POST['creature'];This is when you query the database to get all the info about the creature.
Code: Select all
$creature_info_1 = "SELECT * from creatures where name = '$creature'";
$creature_info_2 = mysql_query($creature_info_1) or die("System: Unable to retrieve creature information.");
$creature_info_3 = mysql_fetch_array($creature_info_2);
-
claymore88
- Posts: 10
- Joined: Tue Aug 16, 2011 8:27 pm
Re: question abou attack
thanks tim. jack I was referring to how you would give each option a different name if. my option displays all creatures with one line..
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: question abou attack
Wait, you have all your creatures in one option tag?
The indelible lord of tl;dr
-
claymore88
- Posts: 10
- Joined: Tue Aug 16, 2011 8:27 pm
Re: question abou attack
maybe I could just make a new table and query what to display