简体   繁体   English

如何将值从函数传递到另一个.php页面

[英]How to pass value from a function to a another .php page

I am trying to delete a record from the database using a button 我正在尝试使用按钮从数据库中删除记录

 <button type="button" onClick="formDelete(<?php echo $proid;?>)">Delete</button> 

I am using the project id to locate the project to be deleted. 我正在使用项目ID来查找要删除的项目。 I am passing this value to a function. 我将此值传递给一个函数。

// 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");

}   

} }

Now I want to pass $proid into deleteproject.php page to run the query to delete it. 现在,我想将$ proid传递到deleteproject.php页面,以运行查询将其删除。 How do I pass the value of project id? 如何传递项目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();
}

} }

?> ?>

Try this way to send your delete item id and get that id on desired page using $_REQUEST before delete that project 尝试以这种方式发送删除的项目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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM