Wednesday 5 September 2018

Why does my SQL LEFT JOIN query not work?

It is returning 0 rows when there should be some results.

This is my first attempt at using JOIN but from what I've read this looks pretty much right, right?
"SELECT pending.paymentid, pending.date, pending.ip, pending.payer, pending.type, pending.amount, pending.method, pending.institution, payment.number, _uploads_log.log_filename
FROM pending
LEFT JOIN _uploads_log
ON pending.paymentid='".$_GET['vnum']."'
AND _uploads_log.linkid = pending.paymentid"

I need to return the specified values from each table where both pending.paymentid and _uploads_log.log_filename are equal to $_GET['vnum]
What is the correct way to do this? Why am I not getting any results?
If someone more experienced than me could point me in the right direction I would be much obliged.
EDIT
For pending the primary key is paymentid, for _uploads_log the primary is a col called log_id and log_filename is listed as index.

Try this
 SELECT  pending.paymentid,
         pending.date,
         pending.ip,
         pending.payer,
         pending.type,
         pending.amount,
         pending.method,
         pending.institution,
         payment.number,
         _uploads_log.log_filename
FROM     pending
         LEFT JOIN _uploads_log
              ON _uploads_log.linkid = pending.paymentid
WHERE   _uploads_log.log_filename = '" . $_GET['vnum']  . "'

Your current query is vulnerable with SQL Injection. Please take time to read the article below.

0 comments:

Post a Comment