Jump to content

Archived

This topic is now archived and is closed to further replies.

supanoob

Searching Database

Recommended Posts

well, i have tried various codes and this is the one i have got now:

My Form (search.php):

[code]<HTML>
<HEAD></HEAD>
<BODY>
<FORM NAME="searchphone" METHOD="post" ACTION="searchres.php">
Enter Last Name: <input name="Array[user]" type="text" id="Array[user]"><BR>
<input type="submit" name="Submit" value="Submit">

</FORM>
</BODY>
</HTML>[/code]

and this is the php (searchres.php):

[code]<HTML>
<HEAD></HEAD>
<BODY>
<FORM NAME="searchphone" METHOD="post" ACTION="searchres.php">
Enter Last Name: <input name="Array[user]" type="text" id="Array[user]"><BR>
<input type="submit" name="Submit" value="Submit">

</FORM>
</BODY>
</HTML>

<HTML>
<HEAD></HEAD>
<BODY>
<?php
$Array["user"] =trim ($Array["user"]);

$Host="i dunt believe it";
$Username="damn";
$Password="hahaha";
$DBName="meh";
$TableName="yeah";
  
$Link = mysql_connect($Host, $Username, $Password);
$Query="SELECT * from $TableName Where user = $Array[user]";
$Result= mysql_db_query ($DBName, $Query, $Link);




echo "Results: <br>$Row[user] ($Row[playerid]) <BR> ";

mysql_close ($Link);
?>
</BODY>
</HTML>[/code]

now i get no errors when searching it just doesnt bring any results up :S

go here to see what i mean:

[a href=\"http://twottk.com/game\" target=\"_blank\"]HERE[/a]

and login using the following:

Username: testacc
password: test123

Share this post


Link to post
Share on other sites
firstly, search.php needs to be modified so that session_start() is the first thing in the page.

PS. you might wanna remove your username & password details from your code that you're sharing with the world.

Share this post


Link to post
Share on other sites
Try this

[code]<HTML>
<HEAD></HEAD>
<BODY>
<FORM NAME="searchphone" METHOD="post" ACTION="searchres.php">
Enter Last Name: <input name="search_query" type="text"><BR>
<input type="submit" name="Submit" value="Submit">

</FORM>
</BODY>
</HTML>

<HTML>
<HEAD></HEAD>
<BODY>
<?php
$search_query = trim($_POST['search_query']);

$Host="i dunt believe it";
$Username="damn";
$Password="hahaha";
$DBName="meh";
$TableName="yeah";
  
$Link = mysql_connect($Host, $Username, $Password);
$Query="SELECT * from $TableName Where user = '$search_query'";
$Result= mysql_db_query ($DBName, $Query, $Link) or die(mysql_error());
$Row = mysql_fetch_array($Result);
$num = mysql_num_rows($Result);
$user = $Row['user'];
$playerid = $Row['playerid'];

if($num == "0"){
echo "Search for $search_query returned no results";
}
else{

echo "Results: <br>$user ($playerid) <BR> ";

}

mysql_close ($Link);
?>
</BODY>
</HTML>[/code]

Share this post


Link to post
Share on other sites
So lets say youre searching for "bob". Then is this what you are getting when you search?

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The search for bob returned no results[/quote]

Share this post


Link to post
Share on other sites
no it wasnt echoeing correctly, well still isnt but now i have loads of errors

Share this post


Link to post
Share on other sites
What kind of errors? you need to be more specific

Share this post


Link to post
Share on other sites
oh i have fixed that now, thanks i might add a tut on it :D show people how i did it etc

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.