通过隐藏字段值显示mysql数据

时间:2013-08-26 05:27:04

标签: php html mysql forms

我试图通过隐藏字段值显示mysql记录,但没有显示任何内容。 一点帮助!

这是代码; HTML:

<form name="form11" method="post" action="hpdata.php" enctype="multipart/form-data">
    <input name="pro" id="pro" type="hidden"  value= "CMS" />
    <input name="piror" id="piror" type="hidden"  value= "P1" />
    <input name="stat" id="stat" type="hidden"  value= "In Progress" />
    <input type="submit" name="submit" id="submit" class="groovybutton" value="...">              
  </form>

PHP:

<?php
    $project = $_POST["pro"];
    $pirority = $_POST["piror"];
    $status = $_POST["stat"];
    mysql_connect ("one", "two", "three");
    mysql_select_db ("wsms");
    $rest = mysql_query("SELECT * FROM sheet WHERE project='$project' AND 
        pirority='$pirority' AND status='$status'");
    while($row = mysql_fetch_array($rest))
    {
        echo $row['id'] . " " . $row['date']; echo "<br>";
    } 
?> 

2 个答案:

答案 0 :(得分:1)

isset放入您的PHP代码

实施例

<?php
if(isset($_POST['submit'])){
   echo  $project = $_POST["pro"]."<br>";
    echo $pirority = $_POST["piror"]."<br>";
    echo $status = $_POST["stat"];
   /* mysql_connect ("one", "two", "three");
    mysql_select_db ("wsms");
    $rest = mysql_query("SELECT * FROM sheet WHERE project='$project' AND 
        pirority='$pirority' AND status='$status'");
    while($row = mysql_fetch_array($rest))
    {
        echo $row['id'] . " " . $row['date']; echo "<br>";
    }*/
}
?>
<form name="form11" method="post" action="" enctype="multipart/form-data">
    <input name="pro" id="pro" type="hidden"  value= "CMS" />
    <input name="piror" id="piror" type="hidden"  value= "P1" />
    <input name="stat" id="stat" type="hidden"  value= "In Progress" />
    <input type="submit" name="submit" id="submit" class="groovybutton" value="...">              
  </form>

输出

CMS
P1
In Progress

答案 1 :(得分:0)

首先检查数据是否来自帖子:

<?php

   echo "<pre>";
   print_r($_POST);
   exit;

?>

如果是,则删除我提供的打印代码,并使用extract($ _ POST);在PHP代码的顶部。您的查询将变为如下:

$rest = mysql_query("SELECT * FROM sheet WHERE project='$pro' AND 
        pirority='$piror' AND status='$stat'");