2 Replies - 516 Views - Last Post: 15 July 2013 - 10:35 PM Rate Topic: -----

#1 adhamu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-July 13

how to use radio button to store datetime in db using php

Posted 15 July 2013 - 09:51 PM

hi,
i want to store date time whan i click radio button(name login time)in mysql. if i click logout radio button it should store logout time.i used now() to store time but it store both values at same time so what is wrong in my code.
<!DOCTYPE html>
<html><head> Employee Login</head>
<body>

<form action="radiocon.php" method="post">
<table border="11">
 <td ><select name="shift">
					  <option value="Day Shift">Day Shift</option>
                        <option value="Night Shift">Night Shift</option>
                        </tr></td>
					
<tr><td><input type="radio" name="login" id= "1">LogIn</td>
<td><input type="radio" name="logout" id= "5">LogOut</td></tr>
<br>
<tr><td><input type="submit" value="Submit"></td><br>
</tr></table></body></html> 
ples help me...
 <?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$data_base="g";
mysql_select_db($data_base, $con);
if($_SERVER['REQUEST_METHOD']=="POST"){
$shift = $_POST['shift'];
$login = $_POST['login'];
$logout = $_POST['logout'];
$sql=("INSERT INTO gg (shift,login,logout)VALUES ('$shift',now(),now())");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
echo "Your Information Was Successfully Posted";
mysql_close($con);
?>


Is This A Good Question/Topic? 0
  • +

Replies To: how to use radio button to store datetime in db using php

#2 nandureddy  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 129
  • Joined: 31-January 11

Re: how to use radio button to store datetime in db using php

Posted 15 July 2013 - 10:34 PM

You should use separate SQL scripts for the login and logout process.
Check out now() function reference.
It seems you are using the deprecated mysql functions in your code.
Please check out mysqli extension and pdo functions here.
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: how to use radio button to store datetime in db using php

Posted 15 July 2013 - 10:35 PM

Quote

so what is wrong in my code

the logic. you do not differentiat in your query, whether it is a login or logout. in fact, the only user input used is the Shift (which also opens you up to all kinds of SQL Injection (see signature)).

to let it make at least some sense, save Shift+Login OR Shift+Logout, based upon which radio was selected.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1