PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 31, 2022

[FIXED] SQL OR not returning all rows

 January 31, 2022     mysql, php, phpmyadmin     No comments   

Issue

I'm having what may be the dumbest issue.
I'm using phpmyadmin and when I query a table using OR it does not return all values.
This is the query that is not returning all values:
SELECT * FROM ecrdatabase.ecrtable m WHERE m.ecrChangeOwner = '$partialOwner' OR m.ecrInitByName = '$partialOwner'.
Here, $partialOwner is passed from $_GET['user'].
Some of the rows are returned - just not all of them. I have a php page that queries the database and I have tried running the query directly on the database through phpmyadmin using query:
SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham'.

Both results from the the direct query and php page return the same number of rows.
I have also tried:
SELECT * FROM ecrtable WHERE (ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham').

What am I missing? I have more complex queries that run fine. Please tell me I'm just missing something stupid...


Solution

You really should be using prepared statements here, first of all. You are wide open to injection attacks.

Second, how do you know that this query does not return all the rows? What queries have you done to verify that this one is wrong?

If you run a union what do you get:

SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham'
UNION ALL
SELECT * FROM ecrtable WHERE ecrInitByName = 'ecunningham')


Answered By - mikeb
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing