Jump to content

HTML form and PHP


Cyph

Recommended Posts

Ok, so I want to load results out of a form in the same page. This shouldn't be a problem.

 

Trying to get it into same page as where the form is, I think the code will make clear what I want to have done.

Have a little experience with PHP, and trying to learn by doing stuff like this. Expect its something really simple.

 

<HTML>
<HEAD>
<title>Pet EXP Calculator</title>
<style type="text/css">
.Note {
font-size: xx-small;
}
</style>
</HEAD>
<body>
<Table border="0">
<?php
if(isset($_POST['submit']))
{
    $PetLVL = $_POST['PetLVL'];
$PetLoyal = $_POST['PetLoya'];
$PetEXP = $_POST['PetEXP'];
$MobLVL = $_POST['MobLVL'];

echo ($PetLVL);
}
?>


<form action="<?=$_SERVER['PHP_SELF']?>">
<tr height="20">
<TD width="100">
Pet Level:</td><td width="70"><input name="PetLVL" type='text' id="PetLVL" size="3" maxlength="3"></input></td>
<td width="100">
Pet Loyalty:</td><td> <select name="PeyLoyal" id="PetLoyal">
<option>0-50</option>
<option>51-150</option>
<option>151-500
<option>501-999</option></option></select></td><tr>
<td>Current EXP Pet:</td> <td><input name="PetEXP" type='text' id="PetEXP" size="8" maxlength="8"></input>
</td>
<td class="Note">
*input the EXP your pet has in stats screen.
</td>
</tr>

</tr>
<tr height="20">
<td width="100">Monster Level:</td><TD><input name="MobLVL" type='text' id="MobLVL" size="3" maxlength="3"></input></td>
<td class="note">*Add ? monsters as level 150</td>
</tr>
<tr>
<td>
<input name="submit" type="submit" value="submit">
</td>
</tr>
</form>
</table>
</body>
</HTML>

Link to comment
https://forums.phpfreaks.com/topic/233118-html-form-and-php/
Share on other sites

Explain what you want to do with the form data. Do you want it echoed in the form fields after the form is submitted or . . . ?

 

But in any event, make this:

<form action="<?=$_SERVER['PHP_SELF']?>">

 

Into this:

<form action="" method ="post">

Link to comment
https://forums.phpfreaks.com/topic/233118-html-form-and-php/#findComment-1198888
Share on other sites

To make sure the $_POST array is populated with the values you think it should have, replace that echo with this and see what it returns when the form is submitted.

echo '<pre>';
print_r($_POST);
echo '</pre>';

Link to comment
https://forums.phpfreaks.com/topic/233118-html-form-and-php/#findComment-1198893
Share on other sites

Nothing seems to be happening still.

 

http://pikorimugadgets.nl/PWI/Pet_Calc.php

Link to the file at the moment.

 

And the code looks like this now:

<?php
if(isset($_POST['submit']))
{
    $PetLVL = $_POST['PetLVL'];
$PetLoyal = $_POST['PetLoya'];
$PetEXP = $_POST['PetEXP'];
$MobLVL = $_POST['MobLVL'];

echo '<pre>';print_r($_POST);echo '</pre>';
}
?>


<form action="" method="post">
<tr height="20">
<TD width="100">
Pet Level:</td><td width="70"><input name="PetLVL" type='text' id="PetLVL" size="3" maxlength="3"></input></td>
<td width="100">
Pet Loyalty:</td><td> <select name="PeyLoyal" id="PetLoyal">
<option>0-50</option>
<option>51-150</option>
<option>151-500
<option>501-999</option></option></select></td><tr>
<td>Current EXP Pet:</td> <td><input name="PetEXP" type='text' id="PetEXP" size="8" maxlength="8"></input>
</td>
<td class="Note">
*input the EXP your pet has in stats screen.
</td>
</tr>

</tr>
<tr height="20">
<td width="100">Monster Level:</td><TD><input name="MobLVL" type='text' id="MobLVL" size="3" maxlength="3"></input></td>
<td class="note">*Add ? monsters as level 150</td>
</tr>
<tr>
<td>
<input name="submit" type="submit" value="submit">
</td>
</tr>

Link to comment
https://forums.phpfreaks.com/topic/233118-html-form-and-php/#findComment-1198896
Share on other sites

<?php
if(isset($_POST['submit']))
{
    $PetLVL = $_POST['PetLVL'];
$PetLoyal = $_POST['PetLoya'];
$PetEXP = $_POST['PetEXP'];
$MobLVL = $_POST['MobLVL'];
}

echo '<pre>';print_r($_POST);echo '</pre>';
?>


<form action="" method="post">
<tr height="20">
<TD width="100">
Pet Level:</td><td width="70"><input name="PetLVL" type='text' id="PetLVL" size="3" maxlength="3"></input></td>
<td width="100">
Pet Loyalty:</td><td> <select name="PeyLoyal" id="PetLoyal">
<option>0-50</option>
<option>51-150</option>
<option>151-500
<option>501-999</option></option></select></td><tr>
<td>Current EXP Pet:</td> <td><input name="PetEXP" type='text' id="PetEXP" size="8" maxlength="8"></input>
</td>
<td class="Note">
*input the EXP your pet has in stats screen.
</td>
</tr>

</tr>
<tr height="20">
<td width="100">Monster Level:</td><TD><input name="MobLVL" type='text' id="MobLVL" size="3" maxlength="3"></input></td>
<td class="note">*Add ? monsters as level 150</td>
</tr>
<tr>
<td>
<input name="submit" type="submit" value="submit">
</td>
</tr>
</form>

 

 

That is what I got now, thxs for being so patient with me.

Link to comment
https://forums.phpfreaks.com/topic/233118-html-form-and-php/#findComment-1198901
Share on other sites

That looks right. Are you getting the values in the $_POST array echoed to the screen looking something like this after you've filled in the form and submitted it?

 

 

Array

(

    [PetLVL] => 100

    [PeyLoyal] => 501-999

    [PetEXP] => 50000

    [MobLVL] => 200

    [submit] => submit

)

 

Link to comment
https://forums.phpfreaks.com/topic/233118-html-form-and-php/#findComment-1198903
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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