Page 1 of 1

How to refresh page using PHP

Posted: Tue Oct 11, 2011 3:23 am
by roopali
Hello Friends
I need your help. I am working on a project in which we want to approve or reject the request. We have created some pages:

First page name is aprove.php

<div id="dataDiv" align="center">
<form id="frmAprove" name="frmAprove" method="post">
<span id="vish">
<?php
include("getAprove.php");
?>
</span>
</form>
</div>

Code for getAprove.php

<style type="text/css">
<!--
.newnew {
color: #060;
font-family: Cambria;
font-size: 16px;
font-weight: bold;
text-decoration: underline;
}
-->
</style>
<?
session_start();
if(!session_is_registered(field1)){
header("location:../login.php");
}
require_once ("../config.php");
$conObj=new conClass();
$con=$conObj->makeCon();

if($con)
{
showData();
}

function showData()
{
$query = "SELECT * FROM `registration` WHERE `Status`=''";
$result = mysql_query($query);
$rnum = mysql_num_rows($result);
if($rnum>0)
{
echo '<div id="align_center">';
echo '<table border="5px">';
echo '<tr>';
echo '<td>';

echo '<table cellspacing="5" width="250">';
for($i=0;$i<$rnum;$i++)
{
echo '<tr>';
echo '<td >';
echo '<a href="SetAproval.php?regID='.mysql_result($result,$i,"RegiID").'" id="btnShow" name="btnShow" class="newnew" />'.mysql_result($result,$i,"Name").'</a>';
//echo '<input type="button" id="btnShow" name="btnShow" value="'.mysql_result($result,$i,"Name").'" onClick="javascript: jsHttpRequest(\'showAprove.php?regID=\', '.mysql_result($result,$i,"RegiID").', \'spanInfo\')" />';
echo '</td>';

echo '<td>';
$param= mysql_result($result,$i,"RegiID");
echo ' <input type="button" id="btnYes" name="btnYes" value="Yes" onClick="javascript: jsHttpRequest(\'putAprove.php?status=yes&param=\', .$param , \'vish\')" />';
echo '</td>';
echo '<td>';
echo ' <input type="button" id="btnNo" name="btnNo" value="No" onClick="javascript: jsHttpRequest(\'putAprove.php?status=no&param=\', .$param , \'vish\')" />';
echo '</td>';
echo '</tr>';
}
echo '</table>';

echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
}
else
{
echo '<table border="3px">';
echo '<tr>';
echo '<td>';
echo '<h3>No Pending Request</h3>';
echo '</td>';
echo '</tr>';
echo '</table>';

}
}

if(isset($_POST['btnYes']))
{
echo "Request Approved";
showData();
}
if(isset($_POST['btnNo']))
{
echo "<script> alert('Request rejected') </script>";
showData();
}
?>

SetAproval.php

<?php
if(isset($_GET['regID']))
{
require_once ("../config.php");
$conObj=new conClass();
$con=$conObj->makeCon();

if($con)
{
$query = "SELECT * FROM `registration` WHERE `RegiID`=".$_GET['regID']."";
$result = mysql_query($query);
$rnum = mysql_num_rows($result);
if($rnum>0)
{
echo '<div id="align_center">';
echo '<table border="0px">';
echo '<tr>';
echo '<td>';
echo '<table cellspacing="5" id="aprovefont">';
echo '<tr>';
echo '<td>';
echo 'Name :';
echo '</td>';
echo '<td>';
echo mysql_result($result,0,"Name");
echo '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>';
echo 'Address :';
echo '</td>';
echo '<td>';
echo mysql_result($result,0,"Address");
echo '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>';
echo 'Designation :';
echo '</td>';
echo '<td>';
echo mysql_result($result,0,"Designation");
echo '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>';
echo 'EmailID :';
echo '</td>';
echo '<td>';
echo mysql_result($result,0,"EmailID");
echo '</td>';
echo '</tr>';

echo '<tr>';
echo '<td>';
echo ' <input type="button" id="btnYes" name="btnYes" value="Yes" onClick="javascript: jsHttpRequest(\'putAprove.php?status=yes&param=\', '.$_GET['regID'].', \'stateSelect\')" />';
echo '</td>';

echo '<td>';
echo ' <input type="button" id="btnNo" name="btnNo" value="No" onClick="javascript: jsHttpRequest(\'putAprove.php?status=no&param=\', '.$_GET['regID'].', \'stateSelect\')" />';
echo '</td>';

echo '</tr>';

echo '</table>';

echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
}
}
}

if(isset($_POST['btnYes']))
{
echo "<script> alert('Request accepted') </script>";
echo "<script> document.location.href='aprove.php' </script>";
}
if(isset($_POST['btnNo']))
{
echo "<script> alert('Request rejected') </script>";
echo "<script> document.location.href='aprove.php' </script>";
}
?>

putAprove.php

<?php
if(isset($_GET['status']))
{
if(isset($_GET['param']))
{
//echo 'status= '.$_GET['status'].'<br/>param= '.$_GET['param'];
require_once ("../config.php");
$conObj=new conClass();
$con=$conObj->makeCon();

if($con)
{
$query = "update `registration` set `Status`='".$_GET['status']."' where RegiID=".$_GET['param'];

$result = mysql_query($query);
$rnum = mysql_affected_rows();
if($rnum>0)
{
echo '<script>';
echo 'alert ("done")';
echo '</script>';
}
}
}
}
?>

jsHttpRequest.js

function jsHttpRequest (src,val,target) {

if (src == "" || val == "" || target == "") {
document.getElementById(target).innerHTML = "";
return;
}

// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest ();
}

// code for IE6, IE5
else {
xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
}


xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById(target).innerHTML = xmlhttp.responseText;
// document.print( xmlhttp.responseText);

}
else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText;
}


}


xmlhttp.open("GET", src+val, true);

xmlhttp.send();



}




This code is working properly for showing detail and update status. But after accepting or rejecting the request we want to show a message and refreshing the page. This is not happening by this code.

Any one knows then please help us.
Thank You with anticipation