Jump to content
#StayAtHome ×

pdo select error

Recommended Posts


I have select statement that will take data from form and add it to select statement but i get this error:

Fatal error
: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':startdate and DATE(ClockingOutDate) <= :enddate ORDER BY o' at line 16 in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php:62 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php(62): PDO->query('SELECT oracleid...') #1 {main} thrown in
on line

this is the code:

<?Php include('session.php');?>

<link rel="stylesheet" type="text/css" href="bootstrap.css">


	<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']))

		$servername = "localhost";
		$username = "rwahdan";
		$password = "fatima2010";
		$sdate1 = $_POST['sdate'];
		$edate1 = $_POST['edate'];

			$conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password);
			// set the PDO error mode to exception

					$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) >= :startdate and DATE(ClockingOutDate) <= :enddate
                    ORDER BY oracleid, clockingindate
					// bind parameters with placeholders

					// execute the query
					// fetch results
					// this will return an array containing all of the rows in the result set
					// check for errors
						if ($prepared->errorCode()!=0) {


problem with where clause conditions but don't know how to deal with this issue.

Share this post

Link to post
Share on other sites

When you're using prepared statements you pass the query string to prepare(). You don't use query() at all.

  • Like 1

Share this post

Link to post
Share on other sites

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.