dnienhaus Posted July 20, 2006 Share Posted July 20, 2006 I am trying to make a simple search for an employee database that just needs to search the partnumber and then return a few fields but i can't get it to work. Any help would be greatly appreciated. Thanks..It jumps straight to this "Search string is empty. Go back and type a string to search."Heres the form:[code]<html><head><title>Searching...</title></head><body bgcolor=#ffffff><h1>Searching the Database</h1><form method="post" action="search.php"><table width=90% align=center><tr><td>search for:</td><td><input type=text name='search' size=60 maxlength=255></td></tr><td></td><td><input type=submit></td></tr></table></form></body></html>[/code]Heres the search.php[code]<?php$username="edit";$password="edit";$database="engineering";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");if($search){$query="SELECT * FROM Assembly WHERE PARTNUMBER='$search'";$result=mysql_db_query($query); if($result){echo "Here are the results:<br><br>";echo "<table width=90% align=center border=1><tr><td align=center bgcolor=#00FFFF><b>Creation Date</b></td><td align=center bgcolor=#00FFFF><b>Creator</b></td><td align=center bgcolor=#00FFFF><b>Nomenclature</b></td><td align=center bgcolor=#00FFFF><b>OBID</b></td><td align=center bgcolor=#00FFFF><b>Part Number</b></td></tr>";while ($r = mysql_fetch_array($result)) { // Begin while$CREATIONDATE = $r["CREATIONDATE"];$CREATOR = $r["CREATOR"];$NOMENCLATURE = $r["NOMENCLATURE"];$OBID = $r["OBID"];$PARTNUMBER = $r["PARTNUMBER"];echo "<tr><td>$CREATIONDATE</td><td>$CREATOR</td><td>$NOMENCLATURE</td><td>$OBID</td><td><b>$PARTNUMBER</b></td></tr><br><br><hr>";} // end whileecho "</table>";} else { echo "problems...."; }} else {echo "Search string is empty. <br> Go back and type a string to search";} ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/ Share on other sites More sharing options...
GingerRobot Posted July 20, 2006 Share Posted July 20, 2006 Ok, perhaps there is something wrong wiith your query; add an or die statement:$result=mysql_db_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61182 Share on other sites More sharing options...
dnienhaus Posted July 20, 2006 Author Share Posted July 20, 2006 still get the same thing :( Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61184 Share on other sites More sharing options...
GingerRobot Posted July 20, 2006 Share Posted July 20, 2006 Ok, well im not sure if if($result) that will work...try:if($result != false) Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61185 Share on other sites More sharing options...
MaaSTaaR Posted July 20, 2006 Share Posted July 20, 2006 and better to write this line[code=php:0]$query="SELECT * FROM Assembly WHERE PARTNUMBER='$search'";[/code]like this[code=php:0]$query="SELECT * FROM Assembly WHERE PARTNUMBER='" . $_POST['search'] . "'";[/code]i mean use $_POST :) mybe you register_globals is off in php.ini Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61186 Share on other sites More sharing options...
dnienhaus Posted July 20, 2006 Author Share Posted July 20, 2006 negative still just getting..Search string is empty.Go back and type a string to search Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61187 Share on other sites More sharing options...
MaaSTaaR Posted July 20, 2006 Share Posted July 20, 2006 Ok , try "LIKE" as alternative for "="[code=php:0]$query="SELECT * FROM Assembly WHERE PARTNUMBER='$search'";[/code]to [code=php:0]$query="SELECT * FROM Assembly WHERE PARTNUMBER LIKE '%" . $_POST['search'] . "%'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61191 Share on other sites More sharing options...
dnienhaus Posted July 20, 2006 Author Share Posted July 20, 2006 damn no good i wish it worked thanks for the input. Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61194 Share on other sites More sharing options...
GingerRobot Posted July 20, 2006 Share Posted July 20, 2006 Try changing this:if($search)toif(!empty($_POST['search'])) Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61200 Share on other sites More sharing options...
dnienhaus Posted July 20, 2006 Author Share Posted July 20, 2006 now i just get a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61201 Share on other sites More sharing options...
MaaSTaaR Posted July 20, 2006 Share Posted July 20, 2006 hmmm , ok better to use mysql_query not mysql_db_query , try .and try to add echo '<h1>test</h1>'; above the query , and see will the page print "test" ? Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61203 Share on other sites More sharing options...
dnienhaus Posted July 20, 2006 Author Share Posted July 20, 2006 you are a php freak! Yeah you fixed it it was the mysql_db_query messing it up! Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/15175-php-simple-search/#findComment-61205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.