mysql查询中的post函数


post function in mysql query

我试图通过post函数创建一个从公式中获取的查询。post函数必须传递一个text和一个int变量才能创建发送到数据库的查询。

当我开始执行php脚本时,它会为int变量显示:undefined index。

我不明白为什么int变量不能被识别。这是我的代码:

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();
?>

哦,

嗯,它只是基本的HTML

<input type="text">

并不意味着内容将是一个字符串,它只是一种输入。

<input type="int">根本不存在。。。

可接受的输入类型(HTML4)

  • 按钮
  • 复选框
  • 文件
  • 隐藏的
  • 图像
  • 密码
  • 无线电
  • 重置
  • 提交
  • 文本

可接受的输入类型(HTML5)

  • 按钮
  • 复选框
  • 颜色
  • 日期
  • 日期时间
  • 本地日期时间
  • 电子邮件
  • 文件
  • 隐藏的
  • 图像
  • 数字
  • 密码
  • 无线电
  • 范围
  • 重置
  • 搜索
  • 提交
  • 电话
  • 文本
  • 时间
  • url

问题在于SQL语句,而不是HTML标记

在您的准备声明中,您有SELECT nomselec,prix但在您的while声明中,您有$donnees['nom']而不是nomselec

这会是问题所在吗?

对于所有说int不是有效类型的人来说,这并不重要,它仍然会正常发布;

示例:

<?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>

退货:

Array ( [possesseur] => test [prixmax] => 123 )

因为没有名为int.的输入类型

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

使用<input type="number">HTML5输入类型为

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