seany123 Posted March 10, 2009 Share Posted March 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/ Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 You retrieve the textboxes the same. You would use $_POST['energy_str']; for the energy_str. Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780821 Share on other sites More sharing options...
seany123 Posted March 10, 2009 Author Share Posted March 10, 2009 so if they put in the textbox 20 then $_POST['energy_str']; be 20? Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780824 Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 That is correct. A good way to see how this stuff works is to create a test page and then just try to echo the values. Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780826 Share on other sites More sharing options...
seany123 Posted March 10, 2009 Author Share Posted March 10, 2009 does this work if all 3 texbox's are written in? Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780827 Share on other sites More sharing options...
seany123 Posted March 10, 2009 Author Share Posted March 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780832 Share on other sites More sharing options...
ngreenwood6 Posted March 10, 2009 Share Posted March 10, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780842 Share on other sites More sharing options...
seany123 Posted March 10, 2009 Author Share Posted March 10, 2009 I understand my code perfectly well I'm just inexperienced in this area of coding. I don't agree with it being very complex its only a few ifs and queries. thanks for help Seany Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-780852 Share on other sites More sharing options...
seany123 Posted March 10, 2009 Author Share Posted March 10, 2009 What im wanting to know is how can i use the value inserted by the member in a query or echo? Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-781692 Share on other sites More sharing options...
ngreenwood6 Posted March 11, 2009 Share Posted March 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-782321 Share on other sites More sharing options...
MainStWebGuy Posted March 17, 2009 Share Posted March 17, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/148704-solved-help-with-forms/#findComment-786992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.