2014-07-20 87 views
-1

當我將隱藏值傳遞給php文件時,它將(true)1作爲答案。無法將隱藏表單值傳遞給php

我將模態值傳遞給php文件。

跨度值是使用jquery檢索的。

PHP代碼:

<?php 
include "dbcon.php"; 
if(isset($_POST['pd_del'])) 
{ 
echo mysql_error(); 
$delid=isset($_POST['delidd']); 
echo $delid; 

}else 
{ 
    echo mysql_error(); 
} 
?> 

HTML代碼:

形式多數民衆贊成派的產品ID到PHP文件

<form name="prd_del" action="del_prod.php" method="post"> 
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="delModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
     <h4 class="modal-title" id="myModalLabel">DELETE PRODUCT</h4> 
     </div> 
     <div class="modal-body"> 
     <h5>Do you want to Delete this Product ??? <span id="delid" name="delid"></span></h5> 
     <input type="hidden" name="delidd" id="delid"> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     <button type="submit" class="btn btn-primary" name="pd_del" >Delete It!</button> 
     </div> 
    </div> 
    </div> 
</div> 
</form> 
+1

你有'ID =「delid」'多個元素 – marekful

+2

你沒有(價值=「中(<輸入型我的價值)=」隱藏的「name =」delidd「id =」delid「>)。你也重複了span中的id() – Tasos

+0

那麼我怎樣才能將span值傳遞給php文件 – user3857836

回答

0

你的HTML:

<h5>Do you want to Delete this Product ??? <span id="delid" name="delid"></span></h5> 
<input type="hidden" name="delidd" id="delid"> 

您的JS:

$(".modal-body #delid").text(pd_del_id); 

第一個問題是,你有2個元素相同的id值(在sppan和輸入字段)。你不應該。

更改您的ID之一,類似的東西:

<h5>Do you want to Delete this Product ??? <span id="delid" name="delid"></span></h5> 
<input type="hidden" name="delidd" id="delid_value"> 

而在你的JS,如果我明白你想要做什麼:

$(".modal-body #delid").text(pd_del_id); // Here you put the product's ID in your span to show it to the user. 
$(".modal-body #delid_value").val(pd_del_id); // Here you put the product's ID in your hidden field to send it with your form. 

現在,你的PHP:

$delid=isset($_POST['delidd']); 
echo $delid; 

isset()函數返回true或false,如果變量設置或不。 設置變量$ _POST ['delidd'](隱藏字段總是發送到您的PHP)。 如果你想獲得的值(您的產品ID):

if (!empty($_POST['delidd'])) { 
// The value is not empty 
    $delid = $_POST['delidd']; 
} else { 
// The value is empty : there is a problem (For example echo an error message or do whatever you have to do in that case.) 
} 
+0

謝謝你的男人..得到它..! – user3857836

+1

不是男人......;)不要忘記保護你的代碼。一個隱藏的字段並不意味着你的用戶不能改變它的值,並把它想要的東西放在它裏面,所以你必須檢查你的$ delid是否是一個int等等。 –