Jump to content

Javascript run php function


jamiet757

Recommended Posts

I am trying to get my site script to send an email to a user when I click on an Approve or Declined link, here is the javascript that handles the clicking:

 

function fstatus(fid,fdo,ftable) {
    var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
document.getElementById('status'+fid).innerHTML =req.responseText;

        }
    }
    req.open(null, 'status.php', true);
    req.send( {'fid':fid,'fdo':fdo,'ftable':ftable} );
}

 

Here is the status.php file:

<?php
include("../function/db.php");
if($_SESSION['entry_admin']!=1){redirect("../auth/");}

include("../../members/JsHttpRequest.php");

$JsHttpRequest =& new JsHttpRequest("iso-8859-1");


$id=(int)@$_REQUEST['fid'];
$doc=@$_REQUEST['ftable'];
$fdo=(int)@$_REQUEST['fdo'];

$sql="select id_parent,published from ".$doc." where id_parent=".$id;
$rs->open($sql);
if(!$rs->eof)
{
$sql="update ".result($doc)." set published=".$fdo." where id_parent=".$id;
$db->execute($sql);

?>
<a href="javascript:fstatus(<?=$rs->row["id_parent"]?>,1,'<?=$doc?>');" <?if($fdo!=1){?>class="gray"<?}?>>Approved</a><br>
<a href="javascript:fstatus(<?=$rs->row["id_parent"]?>,0,'<?=$doc?>');" <?if($fdo!=0){?>class="gray"<?}?>>Pending</a><br>
<a href="javascript:fstatus(<?=$rs->row["id_parent"]?>,2,'<?=$doc?>');" <?if($fdo!=2){?>class="gray"<?}?>>Declined</a>
<?php
}
?>

 

I want to run a php function that will send an email whenever I click one of the links, and I need a way to select which email to send. I can figure out how to get it to send the email, I just can't figure out how to make it happen when I click one of the links. I am not familiar with javascript at all.

Link to comment
https://forums.phpfreaks.com/topic/191552-javascript-run-php-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.