[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using AND condition in Oracle with PHP

Posted on 2009-02-19
8
Medium Priority
?
408 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!!!

0
Comment
Question by:diecasthft
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 23682967
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']}'";
0
 
LVL 7

Expert Comment

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

The above should work.
0
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 23682993
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'] . "'";
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:diecasthft
ID: 23684144
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.
0
 

Author Comment

by:diecasthft
ID: 23684525
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']}'";
0
 
LVL 9

Accepted Solution

by:
absx earned 2000 total points
ID: 23685634
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']."'
";
0
 
LVL 9

Expert Comment

by:absx
ID: 23685645
Eh, language barrier. Apostrophes, not hyphens :>
0
 

Author Closing Comment

by:diecasthft
ID: 31548818
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!!!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question