<td class=mainTxt style="text-align: center;">Mobiltelefon</td>
<td class=mainTxt style="text-align: center;"><?=number_format($mobil);?> kr</td>
<td class=mainTxt style="text-align: center;"><form method="POST"><input type="text" size="4" name="amountm"><input type="hidden" name="special" value="$mobil"></td>
<td class=mainTxt style="text-align: center;"><input type=submit name=selgmob value="Selg"></td>
<td class=mainTxt style="text-align: center;"><input type="hidden" name="special" value="PHONE"><input type=submit name=buymob value="Kjøp"></form></td>
There is my code , but in the last line it is like this:
<input type="hidden" name="special" value="PHONE">
After pressing the button, and using
$ting = $_post['special'];
echo "the special is : $ting ";
In this code, it is not echoing out my hidden form, ( PHONE), that i would like it to do. right now its echoing out: "the special is : "
What is wrong with my code, (and is it possible to improve this?)?
everything works except the hidden value.
The correct way to access post values is to use the predefined variable $_POST
(all capitals). I would also consider using the htmlentities
function to sanitise the incoming data before you display it on your web page.
Also, unless you are going to use the variable $ting
again later, you can cut out the middle-man.
echo "the special is : ".htmlentities($_POST['special']);
Try like
$ting = $_POST['special'];
echo "the special is : ".$ting;
It will be the $_POST
.Not $_post
.
It's $_POST not $_post, it's case-sensitive.
Try changing this line
$ting = $_post['special']; as $ting = $_POST['special'];
html
<form method="post">
<input type="hidden" name="special" value="PHONE">
<input type="submit" name="buymob" value="Kjøp">
</form>
php
<?php
if(isset($_POST['special']))
{
$ting = $_POST['special'];
echo "the special is : $ting ";
}
I reviewed your code, you have that:
<td class=mainTxt style="text-align: center;">Mobiltelefon</td>
<td class=mainTxt style="text-align: center;"><?=number_format($mobil);?> kr</td>
<td class=mainTxt style="text-align: center;">
<form method="POST">
<input type="text" size="4" name="amountm">
<input type="hidden" name="special" value="$mobil">
</td>
<td class=mainTxt style="text-align: center;">
<input type=submit name=selgmob value="Selg">
</td>
<td class=mainTxt style="text-align: center;">
<input type="hidden" name="special" value="PHONE">
<input type=submit name=buymob value="Kjøp">
</form>
</td>
Firstly, you have two "special" inputs, then PHP interpret the first "special" input, after that, the correct PHP code is:
$ting = $_POST['special'];
echo "the special is : $ting ";
Because POST is a PHP keyword, if you don't type the correct keyword, PHP interpret it as simple variable name, in your case, PHP interpreted the value 'special' of the $_post array defined by the programmer, it's different to the $_POST.
I hope this has been helpful.
Good lucky my friend =D