Page 1 of 1

question abou attack

Posted: Tue Aug 16, 2011 8:33 pm
by claymore88
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

Re: question abou attack

Posted: Tue Aug 16, 2011 8:46 pm
by 62896dude
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!

Re: question abou attack

Posted: Tue Aug 16, 2011 9:37 pm
by claymore88
I still get nothing. is there a similar open source script with this feature? I learn best by actually seeing it

Re: question abou attack

Posted: Tue Aug 16, 2011 9:38 pm
by Jackolantern
You forgot the <select> tag, #dude! (Ahh, just saw you meant it as psuedo code)

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>
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.

Re: question abou attack

Posted: Tue Aug 16, 2011 10:31 pm
by claymore88
jack, I see what you mean. but if I list all the creatures with one command how do I give them a different name

Re: question abou attack

Posted: Tue Aug 16, 2011 11:13 pm
by Jackolantern
What do you mean list all the creatures in one command? That is not what I was suggesting.

Re: question abou attack

Posted: Wed Aug 17, 2011 12:03 am
by Tim

Code: Select all

$creature = $_POST['creature'];
The $creature variable will carry the name of the creature, depending on what the user selects. User selects Goblin and hits submit, $creature = Goblin. User selects Orc and hits submit, $creature = Orc.

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);

Re: question abou attack

Posted: Wed Aug 17, 2011 12:14 am
by claymore88
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..

Re: question abou attack

Posted: Wed Aug 17, 2011 12:16 am
by Jackolantern
Wait, you have all your creatures in one option tag?

Re: question abou attack

Posted: Wed Aug 17, 2011 12:35 am
by claymore88
maybe I could just make a new table and query what to display