ramiwahdan Posted March 8, 2020 Share Posted March 8, 2020 I have buttons for clocking in and clocking out at my school. When pressed they will get into DB and record current date and time. how to achieve the on click event in php? <?php include('dbcon.php'); include('session.php'); $result=mysqli_query($con, "select * from staff where OracleID='$session_id'")or die('Error In Session'); $row=mysqli_fetch_array($result); echo("\n"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="form-wrapper"> <center> <h3>Welcome: <?php echo $row['StaffName']; ?> </h3> <?php if ($row['ClockedIn'] == True and $row['ClockedOut'] == False) {echo "You already clockedIn today, please clockOut"; echo '<button hidden> type="button" class="buttonstyle" >Clock Time IN!</button>'; echo '<button type="button" class="buttonstyle">Clock Time OUT!</button>';} ?> <?php if ($row['ClockedOut'] == False and $row['ClockedIn'] == False) {echo '<button type="button" class="buttonstyle" >Clock Time IN!</button>'; echo '<button type="button" class="buttonstyle" >Clock Time OUT!</button>';} ?> <?php if ($row['ClockedIn'] == True and $row['ClockedOut'] == True) {echo "You already clockedIn and ClockedOut today!"; echo '<button hidden> type="button" class="buttonstyle" >Clock Time IN!</button>'; echo '<button hidden> type="button" class="buttonstyle">Clock Time OUT!</button>';} ?> </center> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/310234-button-click-event/ Share on other sites More sharing options...
gw1500se Posted March 8, 2020 Share Posted March 8, 2020 (edited) First, don't embed your PHP code like that. Separate your HTML from the PHP code. Second, don't use * in your select. Extract only those variables you plan to actually use. To do what you want, you need to create a form that submits your data when you click one of the buttons. See this article about using forms and passing data to PHP. Edited March 8, 2020 by gw1500se 1 Quote Link to comment https://forums.phpfreaks.com/topic/310234-button-click-event/#findComment-1575258 Share on other sites More sharing options...
ginerjm Posted March 9, 2020 Share Posted March 9, 2020 Skipping ahead to your actual question - Don't you want to simply do a Submit of your form with that button and not worry about a click? Quote Link to comment https://forums.phpfreaks.com/topic/310234-button-click-event/#findComment-1575270 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.