Jump to content

get value from form field to select statement

Recommended Posts


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.


$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


	<h2>Please enter start date and end date:</h2>
	<form action="#" method="post">
	<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>

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

							<input type="button" onClick="window.print()" value="Print The Report"/>
							<td>Clocking In Time</td>
							<td>Clocking Out Time</td>

	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.

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.