Jump to content

Searching Database


supanoob

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
Link to comment
https://forums.phpfreaks.com/topic/8076-searching-database/
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]
Link to comment
https://forums.phpfreaks.com/topic/8076-searching-database/#findComment-30731
Share on other sites

Archived

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

×
×
  • Create New...

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.