userid not inserted...........

$password=htmlspecialchars($password);
 $sql="SELECT * FROM userregister  WHERE username='$username' and password='$password'";
$result=mysql_query($sql)OR die("Error:".mysql_error());

$row=mysql_num_rows($result);
$userinfo=mysql_fetch_assoc($result);
 $role=$userinfo['role'];
 
 if($row==1){

     $_SESSION['login_user']=$username;
       $_SESSION["userid"] = $id;
  $queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$row[id]}', NOW())";

afterlogin when i isert userid and login time in admin table,,logintime is inserted but userid is showning 0 for all the user:
My Table stucture is
Admin table :
id:
userid:
logintime:
logouttime:
my usertable contain :
id:
username:
password:
role:
LVL 1
manoj kumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try:

 $queryString = "INSERT INTO  admin (userid, intime) VALUES ('$id', NOW())";
0
manoj kumarAuthor Commented:
not working sql query same issue  is there
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try echo it out and see what you get?

$queryString = "INSERT INTO  admin (userid, intime) VALUES ('$id', NOW())"; 
echo $queryString;

Open in new window

0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

manoj kumarAuthor Commented:
it inserted null,i donot understand why it nserted null help me
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
it inserted null,i donot understand why it nserted null help me
so in your existing codes, try check where you assign value to $id
0
manoj kumarAuthor Commented:
i am giving the attachment .when user login it go to authenticate.php after suceesfully authentication user logintime is inserted into database...plz see my code
and my logout.php



<?php
include_once("database-config.php");
      session_start();
      

      $strDateNew=date("d-m-Y H:i:s");
 
      $queryString = "update admin set outtime=NOW()  WHERE  userid = '{$row[id]}' and intime='$strDateNew' ";
        $result1=mysql_query($queryString)OR die("Error:".mysql_error());
  echo "$queryString";
   if(session_destroy())
   {
    header('Location: index.php');
   }
      
   
      
?>
0
manoj kumarAuthor Commented:
i think this area become problem in authenticate.php
$_SESSION['login_user']=$username;
       $_SESSION['userid'] = $row['id'];
 
$queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$row[id]}', NOW())";
  $result1=mysql_query($queryString)OR die("Error:".mysql_error());
 $row1=mysql_num_rows($result1);
plz see
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
if $_SESSION['userid'] = $row['id']; is a valid statement in which $row['id'] contains a non-zero value, then you can try:

... VALUES ('".$row[id]."', NOW())";

$queryString = "INSERT INTO  admin (userid, intime) VALUES ('".$row[id]."', NOW())";

Open in new window

0
Julian HansenCommented:
WHAT WAS THE OUTPUT FROM RYAN's REQUEST
$queryString = "INSERT INTO  admin (userid, intime) VALUES ('$id', NOW())"; 
echo $queryString;

Open in new window


Please post the result from that.

Now look at your code
$row=mysql_num_rows($result);
$userinfo=mysql_fetch_assoc($result);
 $role=$userinfo['role'];
 
 if($row==1){

     $_SESSION['login_user']=$username;
       $_SESSION["userid"] = $id;
  $queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$row[id]}', NOW())";

Open in new window


$row=mysql_num_rows($result); // GET NUMBER OF ROWS
$userinfo=mysql_fetch_assoc($result); // GET THE USER DATA

BUT!!!!!
  $queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$row[id]}', NOW())";
You are using the $row value and not the $userinfo value????
0
manoj kumarAuthor Commented:
can u modlified my authenticate.php and send it
actually i am editing my code bbut same issue is there
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
You are using the $row value and not the $userinfo value????
nice catch Julian :)

so manoj probably forgot to put this line of code:

$id =$userinfo['id']; //assuming the field to get named as "id"

Open in new window


another possible way is using this statement directly:
$queryString = "INSERT INTO  admin (userid, intime) ".
               "SELECT id, Now() FROM userregister  WHERE username='$username' and password='$password' ";

Open in new window

0
Julian HansenCommented:
Just change the $row['id'] in your query to $userinfo['id']
$password=htmlspecialchars($password);
$sql="SELECT * FROM userregister  WHERE username='$username' and password='$password'";
$result=mysql_query($sql)OR die("Error:".mysql_error());

$row=mysql_num_rows($result);
$userinfo=mysql_fetch_assoc($result);
 $role=$userinfo['role'];
 
 if($row==1){

     $_SESSION['login_user']=$username;
       $_SESSION["userid"] = $id;
  $queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$userinfo[id]}', NOW())";

Open in new window

0
manoj kumarAuthor Commented:
air it show:
Notice: Undefined variable: id in C:\xampp\htdocs\test\authenticate.php on line 27($_SESSION["userid"] = $id;)

Notice: Use of undefined constant id - assumed 'id' in C:\xampp\htdocs\test\authenticate.php on line 28($queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$userinfo[id]}', NOW())";);
0
manoj kumarAuthor Commented:
Thanks Ryan Chong and  Julian Hansen: for solving my issue
 thanks a lot
0
Julian HansenCommented:
Missing quotes around the 'id' index.

$password=htmlspecialchars($password);
$sql="SELECT * FROM userregister  WHERE username='$username' and password='$password'";
$result=mysql_query($sql)OR die("Error:".mysql_error());

$row=mysql_num_rows($result);
$userinfo=mysql_fetch_assoc($result);
 $role=$userinfo['role'];
 
 if($row==1){

     $_SESSION['login_user']=$username;
       $_SESSION["userid"] = $id;
  $queryString = "INSERT INTO  admin (userid, intime) VALUES ('{$userinfo['id']}', NOW())";

Open in new window

1
manoj kumarAuthor Commented:
my logout.php when user logout it store 0000-00-00 00:00:00
my logout.php
<?php
include_once("database-config.php");
      session_start();
      

      $strDateNew=date("d-m-Y H:i:s");
 
      $queryString = "update admin set outtime=NOW()  WHERE  userid = '$session[userid]'  and intime='$strDateNew' ";
        $result1=mysql_query($queryString)OR die("Error:".mysql_error());
  echo "$queryString";
   if(session_destroy())
   {
    header('Location: index.php');
   }
      
   
      
?> plz help me
0
manoj kumarAuthor Commented:
i am modify my sql query to
$queryString = "update admin set outtime=NOW()  WHERE  userid = '{$userinfo['id']}'  and intime='$strDateNew' ";
0
Julian HansenCommented:
I don't understand your code.

You have this
$strDateNew=date("d-m-Y H:i:s");

Open in new window

Then you have this
$queryString = "update admin set outtime=NOW()  WHERE  userid = '$session[userid]'  and intime='$strDateNew' ";

Open in new window

Where is intime being set in the Database?
I can't see that this query will EVER work.
$strDateNew will be set to '2018-01-12 12:02:01';
1 second later this value will change
Unless you set intime and then within 1 second (max) you run the query - it is not going to work.
0
manoj kumarAuthor Commented:
sorry:
i will explain it bettrer
i  have logout page where user logout userlogout time will store in mysql database,so i am writing logout.php
<?php
include_once("database-config.php");
      session_start();
       $strDateNew=date("d-m-Y H:i:s");//declare the datatime
      $queryString = "update admin set outtime=NOW()  WHERE  userid = '{$userinfo['id']}'  and intime='$strDateNew' ";(//sql query if user click logout then logout time will store in databse with  which user login and logout))
 $result1=mysql_query($queryString)OR die("Error:".mysql_error());
   if(session_destroy())
   {
    header('Location: index.php');
   }
?>[/b]
0
Julian HansenCommented:
PLEASE .... USE ... CODE ... TAGS!!!!!!!

Still does not make sense. I know what you are trying to do but the way you are doing it does not seem right.
This will set $strDateNew to the CURRENT TIME
 $strDateNew=date("d-m-Y H:i:s");//declare the datatime 

Open in new window

This will have NO EFFECT
$queryString = "update admin set outtime=NOW()  WHERE  
userid = '{$userinfo['id']}'  and 
intime='$strDateNew' ";

Open in new window

It is saying only update records where the intime is ALREADY SET TO THE CURRENT TIME (TO THE SECOND)

It is not going to work!
0
manoj kumarAuthor Commented:
dear sir
how to solve it please send me code
regards
manoj
0
Julian HansenCommented:
how to solve it please send me code
I need to know what you are expecting?

Are you storing a login / logout record for every login / logout event?

I would probably do something like this: NOTE: I am using HEREDOC notation here

$queryString = <<< QUERY
UPDATE
  `admin`
   SET `outtime`=NOW()
   WHERE 
     `userid` = '{$userinfo['id']}' AND 
     `outtime` is NULL
QUERY;

Open in new window

This assumes that your database is setup to put NULL into outtime when you create the record at login.

When you logout - it finds the record that matches the userid and where no outtime has been set.

However, this may be flawed in that there may be records from earlier sessions where a login was done but not a logout - so you need to get around those. You can do it like this
$queryString = <<< QUERY
UPDATE `admin` 
	SET
         `outtime`=NOW()
WHERE  
	`userid` = '{$userinfo['id']}' AND 
	`id` IN (
		SELECT max(`id`) 
		FROM `admin` 
		WHERE `userid` = '{$userinfo['id']}')
QUERY;

Open in new window

What this code does is finds the last record for the user based on record id and sets the outtime on that.

WARNING: NOTE: I have made the assumption that your admin table has an autoincrement column called id. If this is not the case then the above will not work.

PLEASE UPDATE THE ABOVE CODE ACCORDINGLY
0
manoj kumarAuthor Commented:
This is my code
<?php
include_once("database-config.php");
      session_start();
       $strDateNew=date("d-m-Y H:i:s");//declare the datatime
      $queryString = "update admin set outtime=NOW()  WHERE  userid = '{$userinfo['id']}'  and intime='$strDateNew' ";
 $result1=mysql_query($queryString)OR die("Error:".mysql_error());
   if(session_destroy())
   {
    header('Location: index.php');
   }
?>[/b]
0
Julian HansenCommented:
PLEASE, PLEASE, PLEASE Use code tags
ss145.jpg
I don't know what you are asking in your last post. You don't seem to have used any of the suggestions I made in my last post.
0
manoj kumarAuthor Commented:
Sorry sir:
actually how to use this tool some issue is there so i am give my attachment
this is my logout.php
0
manoj kumarAuthor Commented:
<?php
include_once("database-config.php");
      session_start()
;
      
       $queryString ="UPDATE admin SET outtime=NOW() WHERE userid = '{$userinfo['id']}' AND id IN (SELECT max(`id`) FROM admin WHERE userid = '{$userinfo['id']}'";
      $result1=mysql_query($queryString)OR die("Error:".mysql_error());
      
    echo "$queryString";
   
?>
0
Julian HansenCommented:
actually how to use this tool some issue is there so i am give my attachment
Manoj, it is very simple.
1. Paste your code in the comment box
2. Highlight the code (select it)
3. Press the CODE button.

I have no idea what you want me to do with your last post. You posted code but no comment so I don't know if it is working or if there was an error.

I suspect your problem is here
$userinfo['id']
You have not defined that anywhere. I am guessing you need to do this
<?php
session_start();
include_once("database-config.php");
$id = $_SESSION["userid"];      
$queryString ="UPDATE admin SET outtime=NOW() WHERE userid = '{$id}' AND id IN (SELECT max(`id`) FROM admin WHERE userid = '{$id}'";
$result1=mysql_query($queryString)OR die("Error:".mysql_error());

echo "$queryString";

Open in new window

0
manoj kumarAuthor Commented:
It's give Error
Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
0
manoj kumarAuthor Commented:
Here After Solving The Error Gain It Give


Error:You can't specify target table 'admin' for update in FROM clause
0
manoj kumarAuthor Commented:
help me plzzzzzzzzzzzzzzzzzzzzzz
0
Julian HansenCommented:
What was the query that was executed?

Dump it to the screen and post it here

Always show us what you tried to execute - otherwise you are asking us to guess - which is a bad idea
0
manoj kumarAuthor Commented:
i am try to Excute ThisQuery $queryString ="UPDATE admin SET outtime=NOW() WHERE userid = '{$id}' AND id IN (SELECT max(`id`) FROM admin WHERE userid = '{$id}')";
but Eoor Is there say Error:You can't specify target table 'admin' for update in FROM clause
0
Julian HansenCommented:
Change query to
$queryString = <<< QUERY
UPDATE
  `admin`
SET
  `outtime`=NOW()
WHERE
  `userid` = '{$id}' AND
  `id` = (SELECT `maxid` FROM (SELECT MAX(`id`) `maxid` FROM `admin` WHERE `userid` = '{$id}') AS A)
QUERY;

Open in new window

0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
@manoj

you can provide the data dictionary of your tables with some sample data for better understanding.

if userid and id in table: admin are both unique, then we should use only either one for record updating.

what Julian provided earlier of statement below I guess should worked:

$queryString = <<< QUERY
UPDATE
  `admin`
   SET `outtime`=NOW()
   WHERE
     `userid` = '{$userinfo['id']}' AND
     `outtime` is NULL

QUERY;

have you tried above?
0
Julian HansenCommented:
@Ryan
what Julian provided earlier of statement below I guess should worked:
It will but consider this situation.

User logs in - record is created and outtime is NULL intime is today 2018-01-13 12:00:00

User does not log out.

User logs in from different workstation.
A second record is created with intime 2018-01-13 15:00

Now there are two record in the database with outtime 2018-01-13 15:00

This may be ok from the users perspective but it may not.

By linking to the max(id) you should get the last record written which is the one you would want to map to.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
@Julian

that's make sense... and we shall use max(id) to get last entry for that particular user.

@manoj

in some scenario, we could also introduce a "Session ID" (a unique key) to be generated and saved into db to represent/differentiate the current Session. And update record based on this value. This was what i have done for some web applications for my clients.
0
manoj kumarAuthor Commented:
Good Morning Sir, Table for admin
CREATE TABLE IF NOT EXISTS `admin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userid` int(11) NOT NULL,
  `intime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `outtime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=206 ;


Table for User

CREATE TABLE IF NOT EXISTS `user` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `role` varchar(10) NOT NULL,
  `username` varchar(40) NOT NULL,
  `password` varchar(40) NOT NULL
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

But Your Syntaxt Give Error As:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'outtime`=NOW() WHERE userid = '3' AND id = (SELECT `maxid` FROM (SELECT M' at line 1
0
manoj kumarAuthor Commented:
Thank U sir:
Insted Of Showing Userid in FrontEnd Page I wants to Show Username

That Shoud Be This Like :
ID,      User_ID,      Logintime,      Logout_Time,
207      manoj      1/24/2018 10:23      1/24/2018 10:23
207      Kumar      1/24/2018 10:23      1/24/2018 10:23
0
manoj kumarAuthor Commented:
In My Sql
IN Admin Table Logintime is Correct But LOgout Time Shot it 000-000-00-00 00:00:00 This Formmat Why
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Insted Of Showing Userid in FrontEnd Page I wants to Show Username

That Shoud Be This Like :
ID,      User_ID,      Logintime,      Logout_Time,
207      manoj      1/24/2018 10:23      1/24/2018 10:23
207      Kumar      1/24/2018 10:23      1/24/2018 10:23
this is confusing if you're refer to table Admin, in the case you got:

  `userid` int(11) NOT NULL

your table expecting an integer value for userid while you trying to save it as char??
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
or userid in Admin is referring to the Id in user ?
0
manoj kumarAuthor Commented:
so how can i display usnername in FronEnd Page So That  which user Hvae Login and Logot time Display in Proper Manner,Plz Suggest me ,So that Result Will Be UserFriendly Plz Help me
0
manoj kumarAuthor Commented:
I want This Format Result :
id       username       intime                             outime
242       manoj         1/24/2018 10:23      1/24/2018 10:23
243              Kumar         1/24/2218 10:23      1/24/2018 10:22
0
manoj kumarAuthor Commented:
sir plz help me
0
manoj kumarAuthor Commented:
i am waiting for your Replay
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
can you answer my questions below first?

ID: 42434518

ID: 42434519
0
manoj kumarAuthor Commented:
This is id.and it's Type is Double:
0
manoj kumarAuthor Commented:
i cannot understad your Question Plz Explain Me
0
Julian HansenCommented:
Let me try again.
1. Highlight your code
2. Click the CODE button not the B button.
Please please please please use the CODE button.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'outtime`=NOW() WHERE userid = '3' AND id = (SELECT `maxid` FROM (SELECT M' at line 1
What was your full query - you have just posted the error you received for the query but to help you we need to see the FULL query.
0
manoj kumarAuthor Commented:
I am Beginner Of Php from last 1 Month:So i am getting this problem :
Lets See This Code In Jsp,What I Am writing :
<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<head>
<TITLE>Login Application</TITLE>
</head>
<body>
<br><br>
<table align="center" width="400px" border=0>
      <%
      if(session.getAttribute("username")!=null && session.getAttribute("username")!="")
      {
      %>
            <tr>
                  <td align="right" width="350"><a href="home.jsp">Home</a></td>
                  <td align="right"><a href="logout.jsp">Logout</a></td>
            </tr>
      <%
      }
      else
      {
      %>
      <tr>
            <td align="right" width="350"><a href="home.jsp">Home</a></td>
            <td align="right"><a href="login.jsp">Login</a></td>
      </tr>
      <%
      }
      %>
</table>

<table width="400px" align="center" border=0>

      <tr style="background-color:#D9B0D8;">
            <td align="center"><b>User Id</b></td>
            <td align="center"><b>Username</b></td>
            <td align="center"><b>Login</b></td>
            <td align="center"><b>Logout</b></td>
      </tr>
<%

System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/user_register";
String username = "root";
String userPassword = "";
String user = "";

try
{
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      conn = DriverManager.getConnection(url,username,userPassword);
      Statement st = conn.createStatement();
      Statement st1 = conn.createStatement();
      String queryString = "select * from admin order by userid";
      ResultSet rs = st.executeQuery(queryString);
      ResultSet rs1=null;
      String queryStringuser="";
      SimpleDateFormat sdfDestination=null;
      int count=0;
      String strcolor = "";
      while(rs.next())
      {
            count = count%2;
            if(count==0)
            {
                  strcolor = "#D9D9D9";
            }
            else
            {
                  strcolor = "#EFEFEF";
            }
            count++;
            queryStringuser = "select * from userregister where id="+rs.getInt(2);
            rs1 = st1.executeQuery(queryStringuser);
            while(rs1.next())
            {
                  user  = rs1.getString(2);
            }

            String inStr="";
            String outStr="";
            java.util.Date date;
            String intime="";
            String outtime="";
            if((rs.getString(3)!=null && rs.getString(3)!=""))
            {
                  inStr = rs.getString(3).toString().substring(0,rs.getString(3).toString().indexOf("."));
                  try
                  {
                        date = new  SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(inStr);
                        sdfDestination = new SimpleDateFormat("MMM dd, hh:mm:ss");
                        intime = sdfDestination.format(date);
                  }
                  catch (Exception e)
                  {
                        e.getMessage();
                  }
            }

            if((rs.getString(4)!=null && rs.getString(4)!=""))
            {
                  outStr = rs.getString(4).toString().substring(0,rs.getString(3).toString().indexOf("."));
                  try
                  {
                        date = new  SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(outStr);
                        sdfDestination = new SimpleDateFormat("MMM dd, hh:mm:ss");
                        outtime = sdfDestination.format(date);
                  }
                  catch (Exception e)
                  {
                        e.getMessage();
                  }
            }
            %>
            <tr style="background-color:<%=strcolor%>;"><td align="center"><%=rs.getInt(2)%></td><td align="left" style="padding-left:10px;"><%=user%></td><td align="center"><%=intime%></td><td align="center"><%=outtime%></td></tr>
            <%
      }
      conn.close();
}
catch (Exception e)
{
      e.printStackTrace();
}
%>

0
manoj kumarAuthor Commented:
i know java But In This Time I AM in Php:so i am getting this type of issue
Your one question is there in php hot to convert int to char :but in java it is possible because we can type cast int to char,
because Int 4 byte and char 2 so we can use winding if u converrt double to int it is possible in java use Narrowing
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Please please please please use the CODE button.
I think you need read this as well: (click the [?] button in your comment editor)
http://support.experts-exchange.com/customer/portal/articles/2421387
0
manoj kumarAuthor Commented:
Dear Julian
 Actually Application Working fine but i need some change to Display the Result:
I want  to display  All details of user in This format:But i Unable to do that:instead of username my result display userid:i donot want userid i want username
Thanks Jullian
0
manoj kumarAuthor Commented:
Dear Ryan Chong
You Think That I donot Know php,it's Absolutely correct because i am java developer from 1.8 years,but this time this project is going to php:
and i donot have any project so i am doing in php:and i am getting this type of issue:Lets See This code In Java:<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %> <html> <head> <TITLE>Login Application</TITLE> </head> <body> <br><br> <table align="center" width="400px" border=0> <% if(session.getAttribute("username")!=null && session.getAttribute("username")!="") { %> <tr> <td align="right" width="350"><a href="home.jsp">Home</a></td> <td align="right"><a href="logout.jsp">Logout</a></td> </tr> <% } else { %> <tr> <td align="right" width="350"><a href="home.jsp">Home</a></td> <td align="right"><a href="login.jsp">Login</a></td> </tr> <% } %> </table> <table width="400px" align="center" border=0> <tr style="background-color:#D9B0D8;"> <td align="center"><b>User Id</b></td> <td align="center"><b>Username</b></td> <td align="center"><b>Login</b></td> <td align="center"><b>Logout</b></td> </tr> <% System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/user_register"; String username = "root"; String userPassword = ""; String user = ""; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection(url,username,userPassword); Statement st = conn.createStatement(); Statement st1 = conn.createStatement(); String queryString = "select * from admin order by userid"; ResultSet rs = st.executeQuery(queryString); ResultSet rs1=null; String queryStringuser=""; SimpleDateFormat sdfDestination=null; int count=0; String strcolor = ""; while(rs.next()) { count = count%2; if(count==0) { strcolor = "#D9D9D9"; } else { strcolor = "#EFEFEF"; } count++; queryStringuser = "select * from userregister where id="+rs.getInt(2); rs1 = st1.executeQuery(queryStringuser); while(rs1.next()) { user = rs1.getString(2); } String inStr=""; String outStr=""; java.util.Date date; String intime=""; String outtime=""; if((rs.getString(3)!=null && rs.getString(3)!="")) { inStr = rs.getString(3).toString().substring(0,rs.getString(3).toString().indexOf(".")); try { date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(inStr); sdfDestination = new SimpleDateFormat("MMM dd, hh:mm:ss"); intime = sdfDestination.format(date); } catch (Exception e) { e.getMessage(); } } if((rs.getString(4)!=null && rs.getString(4)!="")) { outStr = rs.getString(4).toString().substring(0,rs.getString(3).toString().indexOf(".")); try { date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(outStr); sdfDestination = new SimpleDateFormat("MMM dd, hh:mm:ss"); outtime = sdfDestination.format(date); } catch (Exception e) { e.getMessage(); } } %> <tr style="background-color:<%=strcolor%>;"><td align="center"><%=rs.getInt(2)%></td><td align="left" style="padding-left:10px;"><%=user%></td><td align="center"><%=intime%></td><td align="center"><%=outtime%></td></tr> <% } conn.close(); } catch (Exception e) { e.printStackTrace(); } %> I am Java Developer not php but project in java knot there so i am geeting issue:
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Julian and I trying to help but at the same time, you need to provide the details as clear as possible.

below is based on my assumption. if you got:
SELECT * FROM user;

Open in new window


SnapShot.png
SELECT * FROM admin;

Open in new window


SnapShot1.png
to get your expected result, use query:

select admin.id, user.username, admin.intime, admin.outtime
from admin inner join user
on admin.userid = user.id

Open in new window


Untitled1.png
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
manoj kumarAuthor Commented:
Thanks Ryan
It's Working Fine
0
manoj kumarAuthor Commented:
I Am Trying to Change Password
This Is My Code For Changing The Password:
<?php
require_once 'database-config.php';
if(count($_POST)>0) {
	$_SESSION["id"]=$id;
$result = mysql_query("SELECT * from userregister WHERE id='" . $_SESSION["id"] . "'");
 $row=mysql_fetch_array($result);
  if($_POST["currentPassword"] == $row["password"]) {
  mysql_query("UPDATE userregister set password='" . $_POST["newPassword"] . "' WHERE id='" . $_SESSION["id"] . "'");
  $message = "Password Changed";
} else $message = "Current Password is not correct";
}
?>

Open in new window

But I am geeting Error:Undefined variable: id in C:\xampp\htdocs\change_password.php on line 4
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
But I am geeting Error:Undefined variable: id in C:\xampp\htdocs\change_password.php on line 4
this is quite obvious...  have you define variable $id before you refer to it?

$_SESSION["id"]=$id;

it seems that we are talking the same issue again. if you're using it, you need to define it first... like:
$id = "somevalue";

Open in new window

0
manoj kumarAuthor Commented:
How to Solve it:i tried use Session id:but issue is there:same Error
0
manoj kumarAuthor Commented:
I got it:and solved
Thanks For Suggesting me
0
manoj kumarAuthor Commented:
best solutions
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.