Reputation: 209
I try to create a query getting from a formular through post function. The post function must pass a text and an int variable to create the query sent to database.
When I start execute my php script, it says: undefined index, for the int variable.
I dont understand why the int variable isn't recognized. here is my code:
formulaire04.php
<form action="selection_jeux.php" method="post">
<p>
Nom
<input type="text" name="possesseur"/>
Prix maximum
<input type="int" name="prixmax"/>
<input type="submit" value="Valider"/>
</p>
</form>
selection_jeux.php
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test' , 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('SELECT nomselec, prix FROM jeux_video WHERE possesseur = :possesseur AND prix <= :prixmax');
$req->execute(array('possesseur'=> $_POST['possesseur'], 'prixmax'=> $_POST['prixmax']));
echo '<ul>';
while($donnees = $req->fetch())
{
echo '<li>' . $donnees['nom'] . ' (' . $donnees['prix'] . ' EUR)</li>';
}
echo '<li>';
$req->closeCursor();
?>
Upvotes: 0
Views: 295
Reputation: 60493
Oh,
well, it's just basic HTML
<input type="text">
doesn't mean that content will be a string, it's just a kind of input.
<input type="int">
just doesn't exist...
Accepted types for input (HTML4)
Accepted types for input (HTML5)
Upvotes: 2
Reputation: 1139
use <input type="number">
HTML5 input types are
color
date
datetime
datetime-local
email
month
number
range
search
tel
time
url
week
Upvotes: 0
Reputation: 4173
The issue is in the SQL Statement not the HTML markup
On your prepare statement you have SELECT nomselec,prix but on your while statement you have $donnees['nom'] not nomselec
Could that be the issue?
To all the people saying int isn't a valid type, this does not matter it still gets posted as normal;
Example:
<?php
if(isset($_POST))
{
print_r($_POST);
}
?>
<form action="" method="post">
<p>
Nom
<input type="text" name="possesseur"/>
Prix maximum
<input type="int" name="prixmax"/>
<input type="submit" value="Valider"/>
</p>
</form>
Returns:
Array ( [possesseur] => test [prixmax] => 123 )
Upvotes: 1
Reputation: 3704
Because there is no input type called int.
http://de.selfhtml.org/html/referenz/attribute.htm#input
Upvotes: 1