Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2012, 05:32 AM   PM User | #1
golffor1
New Coder

 
Join Date: Feb 2008
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
golffor1 is an unknown quantity at this point
Select statement isn't working properly

I have the following code
Code:
//query to find the find out if the player_id exsist in the database
			$sql = mysql_query("SELECT Player_number FROM players where Player_First_Name like '$first' AND Player_Last_Name like '$second' AND Inactive_player = 1 AND player_email = '$email' or player_email2 = '$email'") or die ("Find Player Number Error: " .mysql_error()); 
				while($row = mysql_fetch_array($sql))
				{
					$playerID = $row['Player_number'];
					echo $playerID;
					$username = $playerID;
					$isError = "3";
				}
When I tell it to look for valid information it never goes through the while statement, and i don't get an errors. I know it should go through the while statement but I don't see why it isn't.
golffor1 is offline   Reply With Quote
Old 12-08-2012, 10:27 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
LIKE '$first'

Even though you are using LIKE it is still looking for an exact match. You need to include at least one wildcard:

% matches any sequence of characters
_ will match precisely one character


so
PHP Code:
LIKE '$first%' 
will match names that begin with the text of $first.

But I suspect you also need to use brackets ( ) around your ANDs and OR expressions to get the correct logic.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 12-08-2012 at 10:30 AM..
AndrewGSW is offline   Reply With Quote
Old 12-08-2012, 10:31 AM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
.. probably you need this:

PHP Code:
AND (player_email '$email' OR player_email2 '$email'
but that's just an assumption. (I prefer to capitalize SQL keywords.)
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 AM.


Advertisement
Log in to turn off these ads.