supanoob Posted April 18, 2006 Share Posted April 18, 2006 well, i am trying to make a search function to bring up result(s) from my database.this is the actual search form:[code]<?phpsession_start();//this code is compyright to supanoob http://www.twottk.com// to use this code you must have his permission to gain// permission please mail him at [email protected]require_once('header.php');if (!$_SESSION['valid_user']) { echo 'you are not logged in'; die();} $user=$_SESSION['valid_user'];$query="select playerid, user, email, fatigue, maxfat, power, speed, dex, intel, health, maxhealth, gender from players where user='$user'";$result=mysql_query($query);if (!$result){die (mysql_error());}$num_rows=mysql_num_rows($result); // connect to db $usertable = mysql_connect($hostname, $username, $password); mysql_select_db($dbname,$usertable); // The form:?><HTML><HEAD><style type="text/css" media="all"> @import "css.php"; </style> <TITLE>TWOTTK.COM</TITLE></HEAD><TABLE width=100% border=0 cellpadding=0 cellspacing=0><TR> <TD colspan=5> <p align="center"> <img src="http://www.twottk.com/game/banner.jpg" width="730" height="160"></p> <TABLE border=0 cellpadding=0 cellspacing=0> <TR><TD> </TD></TR> </TABLE> </TD></TR><TR height=20><TD colspan=5 align=left><!-- SPACER --></TD></TR><TR> <TD align=left width=5><!-- SPACER --></TD> <TD align=left WIDTH=20% valign=top> <TABLE border=0 cellpadding=0 cellspacing=0 height="85" width="164"> <TR> <TD colspan=2 width=164 height="17"><hr></TD> </TR> <TR> <?phprequire_once('cssloggedin.php');$row=mysql_fetch_array($result);$playerid=($row['playerid']);$user=($row['user']);$fatigue=($row['fatigue']);$maxfat=($row['maxfat']);$power=($row['power']);$speed=($row['speed']);$dex=($row['dex']);$intel=($row['intel']);$health=($row['health']);$maxhealth=($row['maxhealth']);$gender=($row['gender']);?> <TR> <TD colspan=2 width=164 height="30"> Game Stats:<br> ID: <?php echo "$playerid"; ?><br> Gender: <?php echo "$gender"; ?><br> Health: <?php echo "$health / $maxhealth"; ?><br> Fatigue: <?php echo "$fatigue / $maxfat"; ?><hr> <p><hr>Navigation:<br> <a href="home.php">Home</a><br><a href="town.php">Town</a><br><a href="search.php">search</a><br><a href="http://www.twottk.com/game/forum/">Forum</a><br>Account<br><a href="logout.php">Logout<br></a> <hr></p> <hr></TD> </TR> <TR height=20> <TD height="1" width="164"><!-SPACER-></TD> </TR> <TR> <TD colspan=2 width=164 height="1"> </TD> </TR> <TR> <TD width=164 bgcolor=#FFFFFF valign=top height="12"><samp>Logged In: <?php echo date ('jS F'); ?><p></samp></TD> <TD width=1 bgcolor=#FFFFFF height="12"></TD> </TR> <TR> <TD colspan=2 width=164 height="12"><hr> </TD> </TR> </TABLE> <BR> </TD> <TD align=left width=1%><!-- SPACER --></TD> <TD align=left WIDTH=78% valign=top> <TABLE width=744 border=0 cellpadding=0 cellspacing=0 height="12"> <TR> <TD valign=top align=left width=4 height="12"></TD> <TD valign=top align=center background=templates/default/images/menuback.gif width="736" height="12"><hr></TD> <TD valign=top align=right width=4 height="12"></TD> </TR> </TABLE><TABLE width=740 border=0 cellpadding=0 cellspacing=0> <TR> <TD width=1 bgcolor=#FFFFFF></TD> <TD bgcolor=#FFFFFF width="733" ><form method="POST" action="searchres.php">Player ID: <input type="text" name="name"><input type="SUBMIT" value="Search!"></form> <p> </p> <p> </p> <p> </p> <p> </p> <p> </TD> </TR> </TABLE> <p> </p> <TABLE width=748 border=0 cellpadding=0 cellspacing=0 height="39"> <TR> <TD valign=top align=left width=4 height="39"> </TD> <TD align=center background=templates/default/images/menu_bottom.gif width="740" height="39"><hr></TD> <TD valign=top align=right width=4 height="39"> </TD> </TR> </TABLE> <br><CENTER> <p></p> </CENTER> </TD> <TD align=left width=10><!-- SPACER --></TD></TR></TABLE></BODY></HTML>[/code]and this is the action (searchres.php):[code]<?session_start();//this code is copyright to supanoob http://www.twottk.com// to use this code you must have his permission to gain// permission please mail him at [email protected]require_once('header.php');if (!$_SESSION['valid_user']) { echo 'you are not logged in'; die();} $user=$_SESSION['valid_user'];// PHP Search Script$result = mysql_query("select user, playerid from players WHERE playerid LIKE '$name'"); while(list($user, $playerid)=mysql_fetch_array($result)); $query="select playerid, user, email, fatigue, maxfat, power, speed, dex, intel, health, maxhealth, gender from players where user='$user'";$result=mysql_query($query);if (!$result){die (mysql_error());}$num_rows=mysql_num_rows($result);?><HTML><HEAD><style type="text/css" media="all"> @import "css.php"; </style> <TITLE>TWOTTK.COM</TITLE></HEAD><TABLE width=100% border=0 cellpadding=0 cellspacing=0><TR> <TD colspan=5> <p align="center"> <img src="http://www.twottk.com/game/banner.jpg" width="730" height="160"></p> <TABLE border=0 cellpadding=0 cellspacing=0> <TR><TD> </TD></TR> </TABLE> </TD></TR><TR height=20><TD colspan=5 align=left><!-- SPACER --></TD></TR><TR> <TD align=left width=5><!-- SPACER --></TD> <TD align=left WIDTH=20% valign=top> <TABLE border=0 cellpadding=0 cellspacing=0 height="85" width="164"> <TR> <TD colspan=2 width=164 height="17"><hr></TD> </TR> <TR> <?phprequire_once('cssloggedin.php');$row=mysql_fetch_array($result);$playerid=($row['playerid']);$user=($row['user']);$fatigue=($row['fatigue']);$maxfat=($row['maxfat']);$power=($row['power']);$speed=($row['speed']);$dex=($row['dex']);$intel=($row['intel']);$health=($row['health']);$maxhealth=($row['maxhealth']);$gender=($row['gender']);?> <TR> <TD colspan=2 width=164 height="30"> Game Stats:<br> ID: <?php echo "$playerid"; ?><br> Gender: <?php echo "$gender"; ?><br> Health: <?php echo "$health / $maxhealth"; ?><br> Fatigue: <?php echo "$fatigue / $maxfat"; ?><hr> <p><hr>Navigation:<br> <a href="home.php">Home</a><br><a href="town.php">Town</a><br><a href="search.php">search</a><br><a href="http://www.twottk.com/game/forum/">Forum</a><br>Account<br><a href="logout.php">Logout<br></a> <hr></p> <hr></TD> </TR> <TR height=20> <TD height="1" width="164"><!-SPACER-></TD> </TR> <TR> <TD colspan=2 width=164 height="1"> </TD> </TR> <TR> <TD width=164 bgcolor=#FFFFFF valign=top height="12"><samp>Logged In: <?php echo date ('jS F'); ?><p></samp></TD> <TD width=1 bgcolor=#FFFFFF height="12"></TD> </TR> <TR> <TD colspan=2 width=164 height="12"><hr> </TD> </TR> </TABLE> <BR> </TD> <TD align=left width=1%><!-- SPACER --></TD> <TD align=left WIDTH=78% valign=top> <TABLE width=744 border=0 cellpadding=0 cellspacing=0 height="12"> <TR> <TD valign=top align=left width=4 height="12"></TD> <TD valign=top align=center background=templates/default/images/menuback.gif width="736" height="12"><hr></TD> <TD valign=top align=right width=4 height="12"></TD> </TR> </TABLE><TABLE width=740 border=0 cellpadding=0 cellspacing=0> <TR> <TD width=1 bgcolor=#FFFFFF></TD> <TD bgcolor=#FFFFFF width="733" ><form method="POST" action="searchres.php">Player ID: <input type="text" name="name"><input type="SUBMIT" value="Search!"></form><?phpecho "$user ($playerid)";?> <p> </p> <p> </p> <p> </p> <p> </p> <p> </TD> </TR> </TABLE> <p> </p> <TABLE width=748 border=0 cellpadding=0 cellspacing=0 height="39"> <TR> <TD valign=top align=left width=4 height="39"> </TD> <TD align=center background=templates/default/images/menu_bottom.gif width="740" height="39"><hr></TD> <TD valign=top align=right width=4 height="39"> </TD> </TR> </TABLE> <br><CENTER> <p></p> </CENTER> </TD> <TD align=left width=10><!-- SPACER --></TD></TR></TABLE></BODY></HTML>[/code]now the problem is when i have typed in a name (that i know exists) it brings nothing up at all, also it doe not show any of the things the other pages show in the top left of the page ($user, $playerid, $gender etc) it is just a normal page with no php echos at all although the other things in the echo like the () for instance show up.[a href=\"http://twottk.com/game\" target=\"_blank\"]go here to see what i mean.[/a]log in as: Username: testaccPass: test123anyway any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/7757-searching-a-database/ Share on other sites More sharing options...
Caesar Posted April 18, 2006 Share Posted April 18, 2006 Would have been nice if you created a test account so noone here has to register, to see the working (or not working) script. Link to comment https://forums.phpfreaks.com/topic/7757-searching-a-database/#findComment-28297 Share on other sites More sharing options...
wisewood Posted April 19, 2006 Share Posted April 19, 2006 SELECT * FROM your_table WHERE your_field LIKE '%$variable%' ORDER BY whatever_field Link to comment https://forums.phpfreaks.com/topic/7757-searching-a-database/#findComment-28551 Share on other sites More sharing options...
supanoob Posted April 19, 2006 Author Share Posted April 19, 2006 added a test user and pass :D so that should help you. Link to comment https://forums.phpfreaks.com/topic/7757-searching-a-database/#findComment-28760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.