Jump to content


Photo

error trapping on search input box


  • Please log in to reply
3 replies to this topic

#1 87dave87

87dave87
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 23 September 2006 - 01:03 PM

I am trying to create a search box which queries my database tables and if the text entered into the input box is the same as the field 'emulator' then it will return the results of the entire row.

The following code works except when text is entered which doesnt match the 'emulator' field: -

<?php  
$database="mydatabase";  
mysql_connect ("localhost", "user", "pass");  
@mysql_select_db($database) or die( "Unable to select database");
$sql = mysql_query("select * from windows_atari2600 where emulator = '$_POST[emusearch]'");
if(isset($sql)){
while ($get_info = mysql_fetch_row($sql)) {  
  echo "<tr>";  
  foreach ($get_info as $field) echo "<td>$field</td>\n";
  echo "</tr>\n";
}
}else{
  echo "<tr>";
  echo "We cannot find your infomation.";
  echo "</tr>\n";
}
?>


I have also tried the following code but now the results arent shown and any text entered into the input box returns 'We cannot find your information'

<?php  
$database="mydatabase";  
mysql_connect ("localhost", "user", "pass");  
@mysql_select_db($database) or die( "Unable to select database");
$sql = mysql_query("select * from windows_atari2600 where emulator = '$_POST[emusearch]'");
if($sql==""){
while ($get_info = mysql_fetch_row($sql)) {  
  echo "<tr>";  
  foreach ($get_info as $field) echo "<td>$field</td>\n";
  echo "</tr>\n";
}
}else{
  echo "<tr>";
  echo "We cannot find your infomation.";
  echo "</tr>\n";
}
?>

Any help would be greatly appreciated.

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 23 September 2006 - 01:48 PM

<?php  
$database="mydatabase";  
mysql_connect ("localhost", "user", "pass");  
@mysql_select_db($database) or die( "Unable to select database");
$sql = mysql_query("select * from windows_atari2600 where emulator = '$_POST[emusearch]'");
if($sql !== ""){
while ($get_info = mysql_fetch_row($sql)) {  
  echo "<tr>";  
  foreach ($get_info as $field) echo "<td>$field</td>\n";
  echo "</tr>\n";
}
}else{
  echo "<tr>";
  echo "We cannot find your infomation.";
  echo "</tr>\n";
}
?>


need to check that it is NOT eual to ""

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 87dave87

87dave87
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 23 September 2006 - 02:03 PM

what isn't equal to ""?

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 23 September 2006 - 02:12 PM

you put
$sql = mysql_query("select * from windows_atari2600 where emulator = '$_POST[emusearch]'");
if($sql == ""){


but your checking if $sl if equal to nothing then display the data.. but if nothing then no data to display so you need to check that it isnt nothing therefore data returned from query then echo that data.. just try what i put..


Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users