Jump to content

[SOLVED] help with forms.


seany123

Recommended Posts

hey ive made myself a form...

 

<form method='post'><br>
    <table width='80%' align='center'>
        <tr>
            <td rowspan='3' width='10'>
                 </td>
            <td rowspan='3' width='100'>

                 </td>
            <td align='center'><b>Strength</b></td>
            <td align='center'><b>Defense</b></td>
            <td align='center'><b>Speed</b></td>
            <td rowspan='3' width='10'>
                 

            </td>

        <tr>
            <td align='center'><input type='text' name='energy_str' value='0' size='5' maxlength='5'></td>
            <td align='center'><input type='text' name='energy_def' value='0' size='5' maxlength='5'></td>
            <td align='center'><input type='text' name='energy_spd' value='0' size='5' maxlength='5'></td>
        </tr>
        <tr>
            <td align='center'><input type='submit' name='full_strength' value='All Strength'></td>
            <td align='center'><input type='submit' name='full_defense' value='All Defense'></td>
            <td align='center'><input type='submit' name='full_speed' value='All Speed'></td>

        </tr>
        <tr>
            <td colspan='7' align='center'><input type='submit' name='train' value='Train'></td>
        </tr>
    </table>
</form>

 

now i know how to retrieve the buttons using POST[`xxxx`] etc... but i dont know how to retrieve the values from the text boxes and train button.

 

so if someone could just give me a quick hand??

 

thanks

 

 

Link to comment
Share on other sites

i know this is the Html section but Im a little confused on how to use the value...

 

like for the buttons this is the code I used...

 

if ($_POST['full_strength'])
{

$query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $player->energy, $player->awake - $awakeloss, $player->strength + $statgain, $player->total + $statgain, $player->id ));

if ($statgain >= 1){
echo "You trained <?= $player->energy ?> times and gained " . number_format($statgain, 2, ".", ",") . " Strength!!";
}
}
?>

 

basically the buttons make a value in database return to 0...

 

whereas the textbox will only take away 'x' amount.

Link to comment
Share on other sites

I dont exactly know what you are trying to do with the last post, but as a beginner I would think you would want to understand your code before you get into something that complex.

 

As far as the post before that, you will just have to refer to them by the name that you gave them on the form (energy_str, energy_def, energy_spd).

Link to comment
Share on other sites

if the user enters a name in a textbox and hits submit it then "posts" the data. The page that you "posted" to now has that data and can access it by doing "$_POST['name']"(or whatever the name was for the textbox). You can also set that to a variable like so:

 

$name = $_POST['name'];

 

Then all you would have to do is echo $name. A simple example would be this:

 

index.html

<html>
<title>Form</title>
<body>

<form method="post" action="post.php">
Name:
<input type="text" name="name">
<input type="submit" value="post">
</form>

</body>
</html>

 

then post.php

<?php

$name = $_POST['name'];

echo $name;

?>

 

If you copy the code from thsoe two files into the appropriate files and put them on the webserver you will see what I mean if you go to index.html and type in your name and hit submit. I dont think it gets any clearer than that.

Link to comment
Share on other sites

not sure if this helps but i think it should be like this:

 

if ($statgain >= 1){
echo 'You trained "$player->energy" times and gained ' . number_format($statgain, 2, ".", ",") . " Strength!!";
}

 

haven't tested it but i think that's correct - i'm a bit of a newb too though so beware!

Link to comment
Share on other sites

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.