Jump to content

get value from form field to select statement


Recommended Posts

Hi,

I have select statement that has where clause with 3 conditions out of which 2 conditions i need to take values from form in the page.

code:

$res = $conn->query("SELECT oracleid
                         , name 
                         , des 
                         , clockingindate
                         , clockingoutdate  
                         , timediff(clockingoutdate, clockingindate) as duration
                         , total
                    FROM attendance_records
                         JOIN (
                                SELECT oracleid
                                     , sec_to_time(sum(timestampdiff(SECOND, clockingindate, clockingoutdate))) as total
                                FROM attendance_records
								where isdone =-1 
                                GROUP BY oracleid
                              ) tots USING (oracleid)
							  where isdone =-1 and DATE(ClockingOutDate) >= $sdate1 and DATE(ClockingOutDate) <= $edate1
                    ORDER BY oracleid, clockingindate
                    ");

and the form fields names are assigned to variables sdate1 and edate1

code:
 

	<Center>
	
	<h2>Please enter start date and end date:</h2>
	
	</center>
	<form action="#" method="post">
	
	<center>
	<h5>Start Date:<input type="date" name="sdate" placeholder = "Start Date" required="required"></input>
	End Date:<input type="date" name="edate" placeholder = "End Date" required="required"></input>
	<input type="submit" name="saveit" value="Generate"></input></h5>
	</center>
	
	</form>

	<div class="container">
		<div class="row">
			<div class="col m-auto">
				<div class="card mt-5">
					<table class="table table-bordered">
					
						<tr>

							<input type="button" onClick="window.print()" value="Print The Report"/>
							<td>OracleID</td>
							<td>Name</td>
							<td>Designation</td>
							<td>Clocking In Time</td>
							<td>Clocking Out Time</td>
							<td>Duration</td>
						
						</tr>
						
<?php


	if (isset($_POST['saveit']))
								
	{

		$sdate1 = $_POST['sdate'];
		$edate1 = $_POST['edate'];

I tried to run the code didn't work but i take off the 2nd and 3rd conditions of where clause, it works.

Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.