开发者

Unknown column 'Date' in 'where clause'

开发者 https://www.devze.com 2023-02-05 07:41 出处:网络
I have the following query: select * from invoice WHERE Date >= \'$date\' AND status=\'$status\' It returns an error:

I have the following query:

select * from invoice WHERE Date >= '$date' AND status='$status'

It returns an error:

Unknown column 'Date' in 'where clause'

I am not too good in PHP or MYSQL, but I dont see anything wrong. There is probably everything wrong though. I need assistance!

EDIT:

$var = $_GET['date1_year'] ."-" . $_GET['date1_month'] ."-" . $_GET['date1_day'];
$query = "select * from invoice WHERE DateOfCreation >= '$var' AND status='$status'";

And ofcourse it is logged in(authenticated) and is being exec开发者_运维问答uted with no errors, but no proper result either. My DateOfCreation is a DATE type and there are actually the $_GET variables. I want it to search for all records before $var.


select * from invoice WHERE DateOfCreation >= '$date' AND status='$status'

While it would work, I encourage you to look into parameterized queries in order to prevent SQL injection attacks. See here: How can I prevent SQL injection in PHP?


for all records before $var

So you mean this then? (changed >= to <)

$var = $_GET['date1_year'] ."-" . $_GET['date1_month'] ."-" . $_GET['date1_day'];
$query = "select * from invoice WHERE DateOfCreation < '$var' AND status='$status'";

With your EDIT, I assume this error is gone?

Unknown column 'Date' in 'where clause'

0

精彩评论

暂无评论...
验证码 换一张
取 消