Jump to content

unable to display value in in smarty template using ajax and php.........


sunil.23143

Recommended Posts

hello friends i have two files one is index.php and other is login.tpl. i m using ajax in the login.tpl.ajax is working .but the problem is that once ajax sends the value to index.php...but the varibles assigned by index.php are not displayed in login.tpl...just check for fetch3 and fetch5...these are not displayed in lgin.tpl..

this is index.php

<?php



include "smarty.php";
include "config.php";
ini_set('display_errors', 1);

error_reporting(E_ALL);

session_start();
$sql="select * from employees ";
			$fetch3=fetch_mysql_query($sql);
$q=$_GET["q"];
echo "abohar";
echo $q;
echo $q;
echo $q;
echo $q;
echo $q;
echo $q;
$sql="select * from employees where emp_id='$q'";
			$fetch5=fetch_mysql_query($sql);
$cnt=count ($fetch5);
echo "the cont".$cnt."this";

if(isset($_REQUEST['Submit']))
{
echo "sunil abohar";
//echo $mode;
       $email=$_REQUEST['email'];
       $pass=$_REQUEST['pass'];
echo $email;
echo $pass;
$sql="select * from employees where email='$email' and pass='$pass'";
			$fetch=fetch_mysql_query($sql);
			$cnt=count ($fetch);
//echo $cnt;
echo $fetch[0][0];

					if($cnt==0)
					{
						$error='* Invalid Email address or Password !';
						$smarty->assign('error',$error); 
						$mode="";
                                                       echo "nvalid Email address or Password !";
						break;
					}
                                               else
{
if($fetch[0][19]=='suspended')
{
						$error1='* Your account is currently suspended.You can contact the administrator for account activaton !';
						$smarty->assign('error1',$error1); 
						$mode="";
}
else
{

$_SESSION['iidd']=$fetch[0][0];
$_SESSION['name2']=$fetch[0][1];

$mode="userlogin";
echo $mode;

$email="sunil_abohar123@yahoo.co.in";
echo $email;

}
}
}





$login=$_SESSION['iidd'];

if($login != '')
{
   $mode=$_REQUEST['mode'];
}
       
             else
{
$mode="";
}
echo "hum";
echo $fetch4[0][1];
echo $mode;
switch($mode)
{
case('userlogin'):
  {
echo"fdhggggggggbyvdhhdhdfukg";
echo $mode;

if(isset($_REQUEST['Submit']))
{
echo "sk abohar";
echo $mode;
       $email=$_REQUEST['email'];
       $pass=$_REQUEST['pass'];
echo $email;
echo $pass;
$sql="select * from employees where email='$email' and pass='$pass'";
			$fetch=fetch_mysql_query($sql);
			$cnt=count ($fetch);
//echo $cnt;
echo $fetch[0][0];

					if($cnt==0)
					{
						$error='* Invalid Email address or Password !';
						$smarty->assign('error',$error); 
						$mode="";
                                                       echo "nvalid Email address or Password !";
						break;
					}
                                               else
{
if($fetch[0][19]=='suspended')
{
						$error1='* Your account is currently suspended.You can contact the administrator for account activaton !';
						$smarty->assign('error1',$error1); 
						$mode="";
}
else
{

$_SESSION['iidd']=$fetch[0][0];
$_SESSION['name2']=$fetch[0][1];

$mode="userlogin";
echo $mode;
unset($_REQUEST['Submit']);
echo $_REQUEST['Submit'];
$email="sunil_abohar123@yahoo.co.in";
echo $email;
$format="%H:%M:%S";
$login_t=strftime($format);
$_SESSION['login_time1']=$login_t;
echo time();
$_SESSION['login_time']=time();
echo $_SESSION['login_time'];
//echo strtotime($_SESSION['login_time']);
$rep_id=$_SESSION['iidd'];
//echo $login_t;
//echo $rep_id;

$date_today=date('Y-m-d');
echo $date_today;
echo $date_today;

$sql="insert into reports (rep_id,login_t,logout_t,total_dur,date_today) values('$rep_id','$login_t','$logout_t','$total','$date_today')";






	exec_mysql_query($sql);
$sql1 = "Select login_t,logout_t,total_dur from reports where rep_id='$rep_id' and date_today='$date_today'";


$display1=fetch_mysql_query($sql1);
$cnt=count($display1);
$sql1 = "SELECT sum(total_dur) from reports where rep_id='$rep_id' and date_today='$date_today'";


$display2=fetch_mysql_query($sql1);
$cnt=count($display2);
echo "ferozpur";
        echo $cnt;
        echo $cnt;
        echo $cnt;
        echo $cnt;


break;
}
}
}
break;
  }
case("employee"):

  {
echo "dfsfdhjfjsdgkdffffffffffffffffffffffffffffffffffffff";
break;

}
case("logout1"):

  {

  $format="%H:%M:%S";
$logout_t=strftime($format);
//echo 
//echo $logout_t;
//echo $_SESSION['login_time'];

$total_dur=time()-$_SESSION['login_time'];
//echo strtotime($logout_t);
//echo $_SESSION['login_time'];
//echo strtotime("$_SESSION['login_time']");

echo "hellologout".$total_dur."hilogout";
$rep_id=$_SESSION['iidd'];
$login_t=$_SESSION['login_time1'];
$sql="update reports set 
                     logout_t='$logout_t',
                    total_dur=(SELECT SEC_TO_TIME($total_dur))
            
                                           where rep_id='$rep_id' and login_t='$login_t'";

exec_mysql_query($sql);
session_unset();
session_destroy();
unset($_REQUEST['Submit']);
//echo $_REQUEST['Submit'];
        $mode='';
        $log='* You are logged out !';


  	break;

  }
}
echo "hum";
echo $fetch4[0][1];
echo "hum";
echo $fetch4[0][1];
echo "hum";
echo $fetch4[0][1];
echo "hum";
echo $fetch3[0][1];
echo "hum";
echo $fetch3[0][1];
echo "hum";
echo $fetch5[0][2];
$smarty->assign('fetch3',$fetch3);
$smarty->assign('fetch4',$fetch4);
$smarty->assign('fetch5',$fetch5[0][2]);
$smarty->assign('log',$log);
$smarty->assign('display1',$display1);
$smarty->assign('display2',$display2);
$smarty->assign('b',$_SESSION['name2']);
$smarty->assign("mode",$mode);
$smarty->display("index.tpl");
?>

 

this is login.tpl

 

{literal}
<script type="text/javascript">
var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="http://merchant06.com/index.php"
alert (url)
url=url+"?q="+str
alert (url)

xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
} 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
alert ("1")
}
catch (e)
{
//Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

</script>
{/literal}


<table width="100%" border="0" cellpadding="5" cellspacing="0" class="border">
<form name="userl" action="index.php?mode=userlogin" method="post"> 
<tr>
    <td height="5" colspan="2" align="center" valign="middle" bgcolor="#990000"></td>
  </tr>
{if $log eq '<span align="center" style="color:#0000FF"><b> * You are logged out ! </b>                     		</span>'}
  <tr>
    <td height="25" colspan="2" align="center" valign="middle" bgcolor="#f5f3f4" class="blacktext">{$log}</td>
  </tr>
{/if}

{if $forget eq '<span align="center" style="color:#0000FF"><b> * Your password has been sent to your email ! </b>                     		</span>'}
  <tr>
    <td height="25" colspan="2" align="center" valign="middle" bgcolor="#f5f3f4" class="blacktext">{$forget}</td>
  </tr>
{/if}
  <tr>
    <td height="25" colspan="2" align="center" valign="middle" bgcolor="#f5f3f4" class="blacktext">Login {$fetch5}</td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="middle" class="phno">{$error}{$error1}</td>
  </tr>
  <tr>
    <td width="49%" align="right" valign="middle" class="bodytext">User Email : </td>
    <td width="51%" align="left" valign="top">
<form name="userl" action="index.php?mode=employee" method="post"> 
<select name="str" onchange="showUser(this.value)">
<option value="1">Employee ID</option>
{section name=i loop=$fetch3}
<option value="{$fetch3[i].emp_id}">{$fetch3[i].name}</option>
{/section}
</select>
</form>
<p>
<div id="txtHint"><b> your infromgg {$fetch5}
{section name=i loop=$fetch3}
<td>hello {$fetch3[i].name}<td>
{/section}
</b></div>
</p>
</td>
  </tr>
  <tr>

    <td align="right" valign="middle" class="bodytext">{$fetch5}</td>

    <td align="left" valign="top"><input name="pass" type="password" class="text-box" id="pass"></td>
  </tr>
<tr>
{section name=i loop=$fetch4}
    <td width="49%" align="right" valign="middle" class="bodytext">log status : "{$fetch4[i].log_status}" is </td>
{/section}
    <td width="51%" align="left" valign="top">
<select name="log_status">

{section name=i loop=$fetch4}
<option value="{$fetch4[i].emp_id}" selected="selected">{$fetch4[i].log_status}</option>
{/section}
</select>
</td>
  </tr>
  <tr>
    <td align="left" valign="top"> </td>
    <td align="left" valign="top"><input name="Submit" type="submit" class="button" value="Login" onClick="MM_validateForm('email','Email Address :','RisEmail','pass','Password :','R');return document.MM_returnValue"></td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="top"><a href="index.php?mode=forgetpass1">Forgot Password </a></td>
  </tr>
</form>
</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.