[HELP] Search Function

C++, C#, Java, PHP, ect...
Post Reply
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

[HELP] Search Function

Post by srachit »

So I am trying to make a search function for my game and I was wondering if anyone could help me out with it, I am a bit lost (I had the logic behind it one min, I lost it the next :/)

Here is what I have till now

Code: Select all

<center>
<form method= "POST" action = "search.php">
 Search by username: <input type="text" name="sname" size="21"><br>
 Search by nation name: <input type="text" name="nname" size = "21"><br>
 <input type="submit" name="submit" value="submit">
 </form>
</center>

<?php 

if(isset($_POST["submit"]))
{
	$oplayer = $_POST["sname"];
	$nname = $_POST["nname"];
	$oplayer = strip_tags($oplayer);
	$nname = strip_tags($nname);

	if($oplayer)
	{
		$query = "select name from players where name='$oplayer'";
		$result = mysql_query($query) or die("Could not query table");
		$result1 = mysql_fetch_array($result);
		if($result1)
		{
			if(isset($_GET['nation']))
			{$nation = $_GET['nation'];}
			else{$nation = $oplayer;}
		}
}
}
?>
alexrules01
Posts: 175
Joined: Sun Oct 11, 2009 9:33 am

Re: [HELP] Search Function

Post by alexrules01 »

Can't see a problem with it. Are you setting the $_GET['nation']?
Test each if statement and figure out which one isn't working and then work on it from there.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [HELP] Search Function

Post by Jackolantern »

Yes, what exactly is the problem? What is it doing or not doing?
The indelible lord of tl;dr
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

Re: [HELP] Search Function

Post by srachit »

Its pretty much not doing anything at all :P
How do I get my nations page to point at the user searched for and not point at my profile?
alexrules01
Posts: 175
Joined: Sun Oct 11, 2009 9:33 am

Re: [HELP] Search Function

Post by alexrules01 »

From the code above, you are querying the database and trying to retrieve the data in the 'name' column where the username, or, 'oname' matches a value in the name column of the database. And then within the if statement, you are checking if $_GET['nation'] is set.
Can you give more details on what your trying to do? A step by step walkthrough? I'm stumped lol
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: [HELP] Search Function

Post by Chris »

Code: Select all

SELECT name FROM players WHERE name LIKE '%$oplayer%'
OR

Code: Select all

SELECT name FROM players WHERE MATCH (name) AGAINST ($oplayer)
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Coding”