我正在尝试使用按钮
从数据库中删除记录 <button type="button" onClick="formDelete(<?php echo $proid;?>)">Delete</button>
我正在使用项目ID来定位要删除的项目。 我将此值传递给函数。
// deleting a project from the database
function formDelete($proid)
{
var c = "Please confirm your project deletion";
if(c){
$.ajax({
type:"POST",
url:"deleteproject.php",
data:param,
success: function(result)
{
console.log(result);
alert(result);
window.location.href= "http://www.ifunding.co/upload_project.php";
}
});
}
else
{
alert("Please check to confirm deletion of a project");
}
}
现在我想将$ proid传递给deleteproject.php页面来运行查询以删除它。如何传递项目ID的值?
<?php include 'connect.php';
global $db;
$deleteqry="delete from tblproject where project_id='".$proid."'";
$executeqry=mysql_query($deleteqry,$db);
if($executeqry){
$deletedocs="delete from tblprojectdocs where project_id='".$proid."'";
$execute=mysql_query($deletedocs,$db);
if($execute){
$deleteimages="delete from tblprojectimages where project_id='".$proid."'";
$deleteimage=mysql_query($deleteimages,$db);
if($deleteimages){
$success1=1;
}
else
{
$success1=0;
}
if($success1==1){
$success.="Your project has been deleted successfully";
$username = GtUserName($userid);
$from = GtEmailById($userid);
$adminsendto="abc@innovationalfunding.com";
$adminsubject="iFunding: New Project";
$adminbody="<p>Hello Admin,</p>";
$adminbody.="<p><strong>Project has been deleted.</strong></p>";
$adminbody.="<p>Developer Name: ".$username.",</p>";
$adminbody.="<p>Email: ".$from."</p>";
$adminbody.="<p>Project Name: ".$title."</p>";
$adminbody.="<p>Project Description: ".nl2br($description)."</p>";
sendmail($adminsendto,$from,$adminsubject,$adminbody);
echo "Your project has been deleted successfuly.";
}
else{
$errormsg=mysql_error();
}
}
else{
$errormsg=mysql_error();
}
}
&GT;
答案 0 :(得分:0)
尝试这种方式发送您的删除项ID并在删除该项目之前使用$ _REQUEST在所需页面上获取该ID
//button click invode formDelete function
<button type="button" onClick="formDelete(<?php echo $proid;?>)">Delete</button>
function formDelete(proid)
{
var c = "Please confirm your project deletion";
console.log(proid);
var id=proid;
if(c){
$.ajax({
type:"POST",
url:"deleteproject.php",
data:id,
success: function(result)
{
console.log(result);
alert(result);
window.location.href= "http://www.ifunding.co/upload_project.php";
}
});
}
else
{
alert("Please check to confirm deletion of a project");
}
}
//deleteproject.php
print_r($_REQUEST); //will show project delete id
//do your further delete functionality