0

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();
?>
1
  • int isn't a valid value for the type attribute of an HTML <input> element. Commented Sep 7, 2012 at 12:19

4 Answers 4

2

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)

  • button
  • checkbox
  • file
  • hidden
  • image
  • password
  • radio
  • reset
  • submit
  • text

Accepted types for input (HTML5)

  • button
  • checkbox
  • color
  • date
  • datetime
  • datetime-local
  • email
  • file
  • hidden
  • image
  • month
  • number
  • password
  • radio
  • range
  • reset
  • search
  • submit
  • tel
  • text
  • time
  • url
  • week
Sign up to request clarification or add additional context in comments.

1 Comment

The closest to int is type=number which although supported by a few browsers, isn't supoorted by all properly: quirksmode.org/html5/inputs.html#t04
1

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 )

1 Comment

The int was not the main problem you were right. but even with the new code, the screen displays nothing (no error message hopefully)
1

Because there is no input type called int.

http://de.selfhtml.org/html/referenz/attribute.htm#input

Comments

0

use <input type="number"> HTML5 input types are

color
date
datetime
datetime-local
email
month
number
range
search
tel
time
url
week

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.