2014-07-20 58 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等等。 –