簡體   English   中英

如何從PHP中獲取價值?

[英]How to retrieve value on from in php?

我正在嘗試在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:

<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將包含提交兩種形式中的任何一種之后的行數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM