如何从PHP中检索值?

时间:2014-08-30 08:09:57

标签: php mysql

我正在尝试在php页面上检索值,但它没有检索到值。

这是我的代码

检索

<html>
<body>
<?php
include('conn.php');
$per_page = 3; 
if($_GET)
{
$page=$_GET['page'];
}
$start = ($page-1)*$per_page;
$select_table = "select * from clientreg order by id limit $start,$per_page";
$variable = mysql_query($select_table);
?>
<form name="frmUser" method="post" action="">
<div style="width:100%;">
<table border="0" cellpadding="10" cellspacing="1" width="100%" class="tblListForm">
<tr class="listheader">
<td></td>
<td width="230" >*****</td>
</tr>
        <?php
        $i=1;
        $j=0;
        while($row = mysql_fetch_array($variable))
        {
        if($j%2==0)
$classname="evenRow";
else
$classname="oddRow";?>
         <tr class="<?php echo $classname;?>">
<td><input type="checkbox" name="users[]" value="<?php echo $row["id"]; ?>" ></td>
</tr>
        <?php
        $j++;}
        ?>
            <tr class="listheader">
<td colspan="9"><input type="button" name="update" id="onclick" value="Update" /> <input type="button" name="delete" value="Delete"  onClick="setDeleteAction();" />
<input type="button" name="assign" id="assign" value="Assign" onClick="setLeadAssignAction();" />

<?php 
$sql = mysql_query("SELECT *FROM login where  role=1");
while ($row = mysql_fetch_array($sql)){

?>
<tr class="listheader">
<td><input type="checkbox" name="eid[]" value="<?php echo $row["eid"]; ?>" ><?php echo $row["username"]; ?></td>
</tr>


<?php
}
?>
</td>
</tr>
</table>
</div>
</form>

<form class="form" method ="Post"action="" id="contact">
<?php
if(isset($_POST["submit"]) && $_POST["submit"]!="") {
$rowCount = count($_POST["users"]);
for($i=0;$i<$rowCount;$i++) {

$result = mysql_query("SELECT * FROM clientreg WHERE Id='" . $_POST["users"][$i] . "'");
$row[$i]= mysql_fetch_array($result);
echo "shakti";
  echo $row[$i]['id'];
  }
   }
?>

               <img src="button_cancel.png" class="img" id="cancel"/>   

             <div id="left" style="height:400px;width:47%;float:left;margin-left:20px;margin-top:15px;border-radius:10px;">

                <label>Lead Owner: <span>*</span></label>
                <br/>
                <input type="text" name="leadowner[]" id="lead" placeholder="Lead Owner"value=""/><br/>
                <br/>
                <label>First Name: <span>*</span></label>
                <br/>
                <input type="text" name="fname"id="fname" placeholder="Fname"/><br/>
                <br/>
                <label>Last Name: <span>*</span></label>
                <br/>
                <input type="text" name="lname" id="lname" placeholder="Lname"/><br/>
                <br/>
                <label>Mobile No: <span>*</span></label>
                <br/>
                <input type="text" name="mobile"id="mobile" placeholder="Mobile"/><br/>
                <br/>
                <label>Email Id: <span>*</span></label>
                <br/>
                <input type="text"name="email" id="email" placeholder="Email"/><br/>
                </div>
            <input type="submit"  name="submit" value="Submit">
            </form>

</body>
</html>

这段代码我哪里错了?

请解决我的问题

我的问题在这里

 if(isset($_POST["submit"]) && $_POST["submit"]!="") {
    $rowCount = count($_POST["users"]);

任何帮助将不胜感激

我已更新了我的代码并添加了提交按钮。

1 个答案:

答案 0 :(得分:0)

你有两种形式。只有第二个表单有提交。

表格1:

<form name="frmUser" method="post" action="">
<input type="checkbox" name="users[]" value="<?php echo $row["id"]; ?> ">
</form>

表格2:

<form class="form" method ="Post"action="" id="contact">
<input type="submit"  name="submit" value="Submit">
</form>

if构造没有收到$ _POST [“users”],因为它只接收第二个提交表单的POST。

$rowCount = count($_POST["users"]);

$ rowCount将始终为0.

表格2:

...
<?php
$rowCount = 0;
if ($_POST["users"] != "") {
     $rowCount = count($_POST["users"]);
} else if ($_POST["rowcount"] != "") {
     $rowCount = $_POST["rowcount"];
}
?>
...
<form class="form" method ="Post"action="" id="contact">
...
<input type="submit"  name="submit" value="Submit">
<input type="hidden"  name="rowcount" value="<?php echo $rowCount; ?>">
</form>

然后变量$ rowCount将包含提交任何2个表单后的行数。