ramiwahdan Posted March 9, 2020 Share Posted March 9, 2020 Hi, how to set current time to variable then use it to add new record to DB? $loginDate = date("Y-m-d"); $loginTime = ??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/ Share on other sites More sharing options...
ginerjm Posted March 9, 2020 Share Posted March 9, 2020 How about creating a timestamp column and placing a single value on your record instead of two values? Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575307 Share on other sites More sharing options...
ramiwahdan Posted March 9, 2020 Author Share Posted March 9, 2020 4 minutes ago, ginerjm said: How about creating a timestamp column and placing a single value on your record instead of two values? I did make the change but still not inserting! code: <?php include('dbcon.php'); include('session.php'); if (isset($_POST["clockin"])){ $query1=mysqli_query($con, "update staff set ClockedIn = -1, indate = CURDATE() where OracleID='$session_id'")or die('Error In Session'); $result=mysqli_query($con, "select * from staff where OracleID='$session_id'")or die('Error In Session'); $row=mysqli_fetch_array($result); $oracleid = $row['OracleID']; $Name = $row['StaffName']; $Des = $row['Des']; $sDate = date("Y-m-d H:i:s"); $sql = mysqli_query($con,"INSERT INTO attendance_records (OracleID,Name,Des,ClockingInDate) VALUES ('$oracleid','$Name','$Des','$sDate')"); header('location:index.php'); } ?> Still don't see any new records added Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575309 Share on other sites More sharing options...
ginerjm Posted March 9, 2020 Share Posted March 9, 2020 Did you check to see if the first query did an update? And what is the column 'indate' defined as? And did you actually return any rows from the select query? And did you then check to see how many rows were inserted? So many questions that you need to ask of your script. Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575310 Share on other sites More sharing options...
ginerjm Posted March 9, 2020 Share Posted March 9, 2020 Add the use of some mysqli functions: mysqli_affected_rows for the insert and update queries; mysqli_num_rows for the select. Check the manual if you don't know how. Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575313 Share on other sites More sharing options...
Barand Posted March 9, 2020 Share Posted March 9, 2020 What does this SQL query output? DESCRIBE staff; Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575315 Share on other sites More sharing options...
ramiwahdan Posted March 9, 2020 Author Share Posted March 9, 2020 I solved it. the problem was not with time, something else. Now i have a question, when the timestamp got saved, it shows time -3. my time is 9PM for example, it shows in the DB 6PM. Is it saved that way in the server? if i retrieve the time from server and display it, what will it show? 6PM or my time 9PM? I need to show my zone time, how possible? Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575316 Share on other sites More sharing options...
ginerjm Posted March 9, 2020 Share Posted March 9, 2020 You need to set your timezone. It obviously is already incorrect. https://www.php.net/manual/en/function.date-default-timezone-set.php You will have to look up the correct name for your location 1 Quote Link to comment https://forums.phpfreaks.com/topic/310251-set-time-to-variable/#findComment-1575318 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.