Jump to content

AJAX


fareedreg

Recommended Posts

In memadd.php I am passing value of txtmemid to getmember.php and successfully getting name of member in text box but not table to get $totalamt value back.

 

 

 

//memadd.php

function getHTTPObject(){

  if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");

  else if (window.XMLHttpRequest) return new XMLHttpRequest();

  else {

      alert("Your browser does not support AJAX.");

      return null;

  }

 

// Change the value of the outputText field

function setOutput(){

    if(httpObject.readyState == 4){

        document.getElementById('txtmemname').value = httpObject.responseText;

       

    }

 

}

                                                 

function doWork(){   

    httpObject = getHTTPObject();

    if (httpObject != null) {

        httpObject.open("GET", "getmember.php?txtmemid="

                        +document.getElementById('txtmemid').value, true);

        httpObject.send(null);

        httpObject.onreadystatechange = setOutput;

    }

}

 

var httpObject = null;

 

 

 

 

 

 

 

 

//getmember.php

 

<?php

 

if (isset($_GET['txtmemid']))

$memid=($_GET['txtmemid']);

 

 

 

$link = mysql_connect("localhost", "root", "redhat")

or die("Could not connect : " . mysql_error());

 

$Db = "libmanage";

$Tb = "mem_master";

 

mysql_select_db($Db, $link);

                           

$query = "select mem_name from mem_master where mem_id=$memid";

 

$result= mysql_query($query,$link) or die("");

 

 

$fel=mysql_num_fields($result);

$nro=mysql_num_rows($result);

 

if($nro>0)

{

  $row=mysql_fetch_array($result);

  $memname=$row['mem_name'];

 

 

$_GET['txtmemid']=$memname;

 

echo ($_GET['txtmemid']);

 

}

 

else

{

         

    $_GET['txtmemid']="";

    echo ($_GET['txtmemid']);

   

}

 

 

 

mysql_close($link);

 

 

 

 

////Display balance

 

 

$link = mysql_connect("localhost", "root", "redhat")

or die("Could not connect : " . mysql_error());

 

$Db = "libmanage";

$Tb = "mem_depo";

 

mysql_select_db($Db, $link);

                           

$query = "select depo_amt from $Tb where mem_id=$memid";

 

$result= mysql_query($query,$link) or die("");

 

 

$fel=mysql_num_fields($result);

$nro=mysql_num_rows($result);

 

 

$totaldepo=0;

$totalwith=0;

$totaldepoamt=0; 

$i=0;

 

if($nro>0)

{

   

  while($row = mysql_fetch_array($result))

  {

   

        $amt=$row['depo_amt'];   

        $totaldepo=$totaldepo + $amt;

        $i=$i+1;

 

 

  }

 

 

 

/// call withdrawl table

 

$Tb= "mem_with";

 

$query = "select with_amt from $Tb where mem_id=$memid";

 

$result= mysql_query($query,$link) or die("");

 

 

$fel=mysql_num_fields($result);

$nro=mysql_num_rows($result);

 

if($nro>0)

{

   

  while($row = mysql_fetch_array($result))

  {

       

      $amt=$row['with_amt'];   

      $totalwith=$totalwith + $amt;

      $i=$i+1;

 

 

  }

 

 

 

$totalamt=$totaldepo-$totalwith;

 

/// Insert Value into MemberMaster table

 

$Tb= "mem_master";

 

$query = "select * from $Tb where mem_id=$memid";

 

$result= mysql_query($query,$link) or die("");

 

 

$fel=mysql_num_fields($result);

$nro=mysql_num_rows($result);

 

if($nro>0)

{

 

  $sql = ("update $Tb SET balance='$totalamt' where mem_id=$memid");

 

 

  if(!mysql_query($sql, $link))

  die ("Mysql error ....<p>".mysql_error());     

 

 

 

///Display balance

 

$_GET['txtbalance']=$totalamt;

echo ($_GET['txtbalance']);

 

mysql_close($link);

 

 

?>

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/186079-ajax/
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.