On the method of form:
When sending data from a form on PHP, the usual methods are GET
and the POST
. Variables sent with the GET
vain in the URL request, as in the following example:
http://example.com/consulta.php?NumeroCartao=2890127812781233
and shall be recovered in the PHP with $_GET['NumeroCartao']
.
Already sent with POST
, go in the body of the request, and do not appear in the URL. These must be recovered $_POST['NumeroCartao']
.
For your code, you need to make sure you are using the method POST
<form action="consulta.php" method="post">
<label>Numero da Carteira:</label> <span><?php echo $linha['NumeroCartao'];?></span>
<div>
<input class="numerocarteira" id="NumeroCartao" name="NumeroCartao" type="hidden" value="<?php echo $linha['NumeroCartao']; ?>" />
<input id="NumeroCartaoDis" name="NumeroCartaoDis" type="text" disabled="" value="<?php echo $linha['NumeroCartao']; ?>" />
</div>
</form>
Other considerations:
Not directly linked to the form, but you can take advantage and use simple quotes in this case:
echo 'NUMERO CARTA0 {'.$NumeroCartao.'}';
With double quotes, the character {
has a special function in the PHP to interpret variables, better always avoid ambiguities.
Although the PHP allow this format:
<?= $linha['NumeroCartao']; ?>
give preference to the long version whenever you can:
<?php echo $linha['NumeroCartao']; ?>
Thus, your application will become more portable if one day it goes to a server where the short tags <?
are disabled.
You can post the code that is between
<form>
and</form>
?– Leonel Sanches da Silva
The
echo $linha['NumeroCartao']
displays the value correctly?– abfurlan
No use <form> ajax use!
– alexjosesilva