Current location: Hot Scripts Forums » Programming Languages » PHP » SQL Query Paramater Precedence?


SQL Query Paramater Precedence?

Reply
  #1 (permalink)  
Old 09-03-06, 12:17 PM
Rahil Rahil is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Toronto, Ontario, Canada
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Smile SQL Query Paramater Precedence?

Hi everyone,

I'm working on a script where you can view a submission and see if there is already a submission with a similar name or email address in the database. The following SQL query doesn't seem to return the right results. It keeps showing me the same row we're looking at (ie the ID!='$id' isn't working). I think it has something to do with paramater precedence:

PHP Code:

// ID cannot equal $id because we don't want the query to return the same row we're looking at

$sql "SELECT ID,Artist_name,Artist_email,Artist_URL,Artist_URLtitle FROM gallery_submissions WHERE ID!='$id' AND Artist_name LIKE '$Artist_name' OR Artist_email LIKE '$Artist_email'"
However, the following simple query excludes the same row we're looking at:

PHP Code:

$sql "SELECT ID,Artist_name,Artist_email,Artist_URL,Artist_URLtitle FROM gallery_submissions WHERE ID!='$id'"
Can anyone shed some let on this issue? I hope I was clear enough. Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 09-03-06, 12:53 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
You are right about the cause of this. If we assume that the email has a match, your query evaluates as follows:

WHERE ID!='$id' AND Artist_name LIKE '$Artist_name' OR Artist_email LIKE '$Artist_email'

WHERE anything (id) AND anything (name) OR true (email). The OR will return anything with a matching email.

Use ( ) to force the evaluation logic that you want.

I suspect you want - WHERE ID!='$id' AND (Artist_name LIKE '$Artist_name' OR Artist_email LIKE '$Artist_email')
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 09-03-06, 01:20 PM
Rahil Rahil is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Toronto, Ontario, Canada
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you soo much mab! What you said worked perfectly
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL db - custom insert and select query app needed ATS16805 ASP.NET 1 06-24-05 04:38 PM
SQL Query Sting Help ksroadrunner13 ASP 1 10-17-04 02:56 PM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 07:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.