We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Using AND condition in Oracle with PHP

diecasthft
diecasthft asked
on
Medium Priority
422 Views
Last Modified: 2013-12-18
I have a query that I've built in PHP, using ORACLE...And I'm really not well versed in php but I thought this should work....the problem seems to be with my AND statemeny:

$query = "SELECT * FROM I3AR.BUILDING where INSTALLATION.GEOGRAPHIC_LOCATION_CODE = \'02341\' AND
BUILDING.BUILDING_NUMBER = '{$_GET['Building_id']}";

If I break this apart and run the two seperate queries without the AND, each one works...but I get too much information which is why I wanted the AND statement. When I out it together, it fails. I keep getting different error messages about quotes depending on what I change. CAn anyone help me with this?? Thanks Alot!!!

Comment
Watch Question

CERTIFIED EXPERT

Commented:
You seem to be missing a single quote near the end.  Try this:

$query = "SELECT * FROM I3AR.BUILDING where INSTALLATION.GEOGRAPHIC_LOCATION_CODE = \'02341\' AND
BUILDING.BUILDING_NUMBER = '{$_GET['Building_id']}'";
$query = "SELECT * FROM I3AR.BUILDING where INSTALLATION.GEOGRAPHIC_LOCATION_CODE ='02341' AND BUILDING.BUILDING_NUMBER = '{".$_GET['Building_id']."}";

The above should work.
CERTIFIED EXPERT

Commented:
Maybe try and break it out like this:

$query = "SELECT * FROM I3AR.BUILDING where INSTALLATION.GEOGRAPHIC_LOCATION_CODE = \'02341\' AND
BUILDING.BUILDING_NUMBER = '" . $_GET['Building_id'] . "'";

Author

Commented:
I'm afraid none of these options worked. I either get the error ORA-00911 Invalid Character or ORA-01756: quoted string not properly terminated. I thought maybe the value wasn't coming thru from the url, but I put a line in there to make sure I was getting it...and the selected building number does display correctly from that line.

Author

Commented:
Also, I had a mistake in my code...it didn't change the reults, but it should have been:

$query = "SELECT * FROM I3AR.BUILDING where BUILDING.GEOGRAPHIC_LOCATION_CODE = \'02341\' AND
BUILDING.BUILDING_NUMBER = '{$_GET['Building_id']}'";

not:

$query = "SELECT * FROM I3AR.BUILDING where INSTALLATION.GEOGRAPHIC_LOCATION_CODE = \'02341\' AND
BUILDING.BUILDING_NUMBER = '{$_GET['Building_id']}'";
Commented:
Why would you escape the hyphens with a backslash like that?


$query = "
  SELECT
    *
  FROM
    I3AR.BUILDING
  where
    INSTALLATION.GEOGRAPHIC_LOCATION_CODE = '02341'
    AND BUILDING.BUILDING_NUMBER = '".$_GET['Building_id']."'
";

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Eh, language barrier. Apostrophes, not hyphens :>

Author

Commented:
I don't know why I would do that...except that it worked as an individual query....and then didn't when I tried to add the AND....this php thing is going to mess me up a little...what I do know is your way works!!! Thanks Alot!!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.