manoj kumar
asked on
userid not inserted...........
$password=htmlspecialchars ($password );
$sql="SELECT * FROM userregister WHERE username='$username' and password='$password'";
$result=mysql_query($sql)O R die("Error:".mysql_error() );
$row=mysql_num_rows($resul t);
$userinfo=mysql_fetch_asso c($result) ;
$role=$userinfo['role'];
if($row==1){
$_SESSION['login_user']=$u sername;
$_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:
$sql="SELECT * FROM userregister WHERE username='$username' and password='$password'";
$result=mysql_query($sql)O
$row=mysql_num_rows($resul
$userinfo=mysql_fetch_asso
$role=$userinfo['role'];
if($row==1){
$_SESSION['login_user']=$u
$_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:
ASKER
not working sql query same issue is there
try echo it out and see what you get?
$queryString = "INSERT INTO admin (userid, intime) VALUES ('$id', NOW())";
echo $queryString;
ASKER
it inserted null,i donot understand why it nserted null help me
it inserted null,i donot understand why it nserted null help meso in your existing codes, try check where you assign value to $id
ASKER
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-con fig.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($quer yString)OR die("Error:".mysql_error() );
echo "$queryString";
if(session_destroy())
{
header('Location: index.php');
}
?>
and my logout.php
<?php
include_once("database-con
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($quer
echo "$queryString";
if(session_destroy())
{
header('Location: index.php');
}
?>
ASKER
i think this area become problem in authenticate.php
$_SESSION['login_user']=$u sername;
$_SESSION['userid'] = $row['id'];
$queryString = "INSERT INTO admin (userid, intime) VALUES ('{$row[id]}', NOW())";
$result1=mysql_query($quer yString)OR die("Error:".mysql_error() );
$row1=mysql_num_rows($resu lt1);
plz see
$_SESSION['login_user']=$u
$_SESSION['userid'] = $row['id'];
$queryString = "INSERT INTO admin (userid, intime) VALUES ('{$row[id]}', NOW())";
$result1=mysql_query($quer
$row1=mysql_num_rows($resu
plz see
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())";
... VALUES ('".$row[id]."', NOW())";
$queryString = "INSERT INTO admin (userid, intime) VALUES ('".$row[id]."', NOW())";
WHAT WAS THE OUTPUT FROM RYAN's REQUEST
Please post the result from that.
Now look at your code
$row=mysql_num_rows($resul t); // GET NUMBER OF ROWS
$userinfo=mysql_fetch_asso c($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????
$queryString = "INSERT INTO admin (userid, intime) VALUES ('$id', NOW())";
echo $queryString;
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())";
$row=mysql_num_rows($resul
$userinfo=mysql_fetch_asso
BUT!!!!!
$queryString = "INSERT INTO admin (userid, intime) VALUES ('{$row[id]}', NOW())";
You are using the $row value and not the $userinfo value????
ASKER
can u modlified my authenticate.php and send it
actually i am editing my code bbut same issue is there
actually i am editing my code bbut same issue is there
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"
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' ";
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())";
ASKER
air it show:
Notice: Undefined variable: id in C:\xampp\htdocs\test\authe nticate.ph p on line 27($_SESSION["userid"] = $id;)
Notice: Use of undefined constant id - assumed 'id' in C:\xampp\htdocs\test\authe nticate.ph p on line 28($queryString = "INSERT INTO admin (userid, intime) VALUES ('{$userinfo[id]}', NOW())";);
Notice: Undefined variable: id in C:\xampp\htdocs\test\authe
Notice: Use of undefined constant id - assumed 'id' in C:\xampp\htdocs\test\authe
ASKER
Thanks Ryan Chong and Julian Hansen: for solving my issue
thanks a lot
thanks a lot
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())";
ASKER
my logout.php when user logout it store 0000-00-00 00:00:00
my logout.php
<?php
include_once("database-con fig.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($quer yString)OR die("Error:".mysql_error() );
echo "$queryString";
if(session_destroy())
{
header('Location: index.php');
}
?> plz help me
my logout.php
<?php
include_once("database-con
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($quer
echo "$queryString";
if(session_destroy())
{
header('Location: index.php');
}
?> plz help me
ASKER
i am modify my sql query to
$queryString = "update admin set outtime=NOW() WHERE userid = '{$userinfo['id']}' and intime='$strDateNew' ";
$queryString = "update admin set outtime=NOW() WHERE userid = '{$userinfo['id']}' and intime='$strDateNew' ";
I don't understand your code.
You have this
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.
You have this
$strDateNew=date("d-m-Y H:i:s");
Then you have this$queryString = "update admin set outtime=NOW() WHERE userid = '$session[userid]' and intime='$strDateNew' ";
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.
ASKER
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-con fig.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($quer yString)OR die("Error:".mysql_error() );
if(session_destroy())
{
header('Location: index.php');
}
?>[/b]
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-con
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($quer
if(session_destroy())
{
header('Location: index.php');
}
?>[/b]
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
It is not going to work!
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
This will have NO EFFECT$queryString = "update admin set outtime=NOW() WHERE
userid = '{$userinfo['id']}' and
intime='$strDateNew' ";
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!
ASKER
dear sir
how to solve it please send me code
regards
manoj
how to solve it please send me code
regards
manoj
how to solve it please send me codeI 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;
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;
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
ASKER
This is my code
<?php
include_once("database-con fig.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($quer yString)OR die("Error:".mysql_error() );
if(session_destroy())
{
header('Location: index.php');
}
?>[/b]
<?php
include_once("database-con
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($quer
if(session_destroy())
{
header('Location: index.php');
}
?>[/b]
ASKER
Sorry sir:
actually how to use this tool some issue is there so i am give my attachment
this is my logout.php
actually how to use this tool some issue is there so i am give my attachment
this is my logout.php
ASKER
<?php
include_once("database-con fig.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($quer yString)OR die("Error:".mysql_error() );
echo "$queryString";
?>
include_once("database-con
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($quer
echo "$queryString";
?>
actually how to use this tool some issue is there so i am give my attachmentManoj, 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";
ASKER
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
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
ASKER
Here After Solving The Error Gain It Give
Error:You can't specify target table 'admin' for update in FROM clause
Error:You can't specify target table 'admin' for update in FROM clause
ASKER
help me plzzzzzzzzzzzzzzzzzzzzzz
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
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
ASKER
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
but Eoor Is there say Error:You can't specify target table 'admin' for update in FROM clause
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;
@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?
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?
@Ryan
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.
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.
@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.
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.
ASKER
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
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
ASKER
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
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
ASKER
In My Sql
IN Admin Table Logintime is Correct But LOgout Time Shot it 000-000-00-00 00:00:00 This Formmat Why
IN Admin Table Logintime is Correct But LOgout Time Shot it 000-000-00-00 00:00:00 This Formmat Why
Insted Of Showing Userid in FrontEnd Page I wants to Show Usernamethis is confusing if you're refer to table Admin, in the case you got:
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
`userid` int(11) NOT NULL
your table expecting an integer value for userid while you trying to save it as char??
or userid in Admin is referring to the Id in user ?
ASKER
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
ASKER
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
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
ASKER
sir plz help me
ASKER
i am waiting for your Replay
can you answer my questions below first?
ID: 42434518
ID: 42434519
ID: 42434518
ID: 42434519
ASKER
This is id.and it's Type is Double:
ASKER
i cannot understad your Question Plz Explain Me
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.
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 1What 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.
ASKER
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.ut il.*,java. text.*,jav a.text.Sim pleDateFor mat" %>
<html>
<head>
<TITLE>Login Application</TITLE>
</head>
<body>
<br><br>
<table align="center" width="400px" border=0>
<%
if(session.getAttribute("u sername")! =null && session.getAttribute("user name")!="" )
{
%>
<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:#D 9B0D8;">
<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:33 06/user_re gister";
String username = "root";
String userPassword = "";
String user = "";
try
{
Class.forName("com.mysql.j dbc.Driver ").newInst ance();
conn = DriverManager.getConnectio n(url,user name,userP assword);
Statement st = conn.createStatement();
Statement st1 = conn.createStatement();
String queryString = "select * from admin order by userid";
ResultSet rs = st.executeQuery(queryStrin g);
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(queryStri nguser);
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.getS tring(3).t oString(). 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.getS tring(3).t oString(). 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.getIn t(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();
}
%>
Lets See This Code In Jsp,What I Am writing :
<%@ page import="java.sql.*,java.ut
<html>
<head>
<TITLE>Login Application</TITLE>
</head>
<body>
<br><br>
<table align="center" width="400px" border=0>
<%
if(session.getAttribute("u
{
%>
<tr>
<td align="right" width="350"><a href="home.jsp">Home</a></
<td align="right"><a href="logout.jsp">Logout</
</tr>
<%
}
else
{
%>
<tr>
<td align="right" width="350"><a href="home.jsp">Home</a></
<td align="right"><a href="login.jsp">Login</a>
</tr>
<%
}
%>
</table>
<table width="400px" align="center" border=0>
<tr style="background-color:#D
<td align="center"><b>User Id</b></td>
<td align="center"><b>Username
<td align="center"><b>Login</b
<td align="center"><b>Logout</
</tr>
<%
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:33
String username = "root";
String userPassword = "";
String user = "";
try
{
Class.forName("com.mysql.j
conn = DriverManager.getConnectio
Statement st = conn.createStatement();
Statement st1 = conn.createStatement();
String queryString = "select * from admin order by userid";
ResultSet rs = st.executeQuery(queryStrin
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(queryStri
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()
try
{
date = new SimpleDateFormat("yyyy-MM-
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()
try
{
date = new SimpleDateFormat("yyyy-MM-
sdfDestination = new SimpleDateFormat("MMM dd, hh:mm:ss");
outtime = sdfDestination.format(date
}
catch (Exception e)
{
e.getMessage();
}
}
%>
<tr style="background-color:<%
<%
}
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
%>
ASKER
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
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
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
ASKER
ASKER
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:
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:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ryan
It's Working Fine
It's Working Fine
ASKER
I Am Trying to Change Password
This Is My Code For Changing The Password:
sword.php on line 4
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";
}
?>
But I am geeting Error:Undefined variable: id in C:\xampp\htdocs\change_pasBut I am geeting Error:Undefined variable: id in C:\xampp\htdocs\change_pasthis is quite obvious... have you define variable $id before you refer to it?sword.php on line 4
$_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";
ASKER
How to Solve it:i tried use Session id:but issue is there:same Error
ASKER
I got it:and solved
Thanks For Suggesting me
Thanks For Suggesting me
ASKER
best solutions
$queryString = "INSERT INTO admin (userid, intime) VALUES ('$id', NOW())";