Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-21-2006, 10:59 PM Search DB Problem
Novice Talker

Posts: 10
Trades: 0
I want to be able to search any fields in the DB I have. I have this code:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Search Results</title>
</head>

<body>
<a href="insert2.php" target="_self" name="DB Home">DB Main Page</a>
<?

$username
="******";
$password="*****";
$database="testdb";
mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");

if (
$search// perform search only if a string was entered.
{
mysql_connect() or die ("Problem connecting to DataBase");
$srch="%".$search."%";
$query "SELECT coords, name, owner, defense, comments FROM planets WHERE coords = '%$search%' OR  name = '%$search%' OR owner = '%$search%' OR defense = '%$search%' OR comments = '%$search%'";

$result mysql_db_query("testdb"$query);

if (
$result)
{
echo 
"Here are the results:<br><br>";
echo 
"<table width=90% align=center border=1>
<tr>
<td align=center bgcolor=#00FFFF>Coordinates</td>
<td align=center bgcolor=#00FFFF>Name</td>
<td align=center bgcolor=#00FFFF>Owner</td>
<td align=center bgcolor=#00FFFF>Defense</td>
<td align=center bgcolor=#00FFFF>Comments</td>
</tr>"
;

while (
$r mysql_fetch_array($result)) { // Begin while
$coords $r["coords"];
$name $r["name"];
$owner $r["owner"];
$defense $r["defense"];
$comments $r["comments"];
echo 
"<tr>
<td>
$coords</td>
<td>
$name</td>
<td>
$owner</td>
<td>
$defense</td>
<td>
$comments</td>
</tr>"
;
// end while
echo "</table>";
} else { echo 
"problems...."; }
} else {
echo 
"Search string is empty. <br> Go back and type a string to search";
}

?>



</body>
</html>
It seems to work if someone just clicks the link without any data. It returns what it is supposed to. Now when there is data submitted it returns "problems..."

Can anyone please help me with this?
avis is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-24-2006, 02:06 PM Re: Search DB Problem
Experienced Talker

Posts: 47
Trades: 0
I typed a very long answer and it got lost in the automatic timer logout thingie.....

So here is the short version:

Your If/Else logic is confused. Try a test like IF (!$result) to eliminate the first error condition (no data entered) and simplify the rest with only one Else?

Frodocyber
Frodocyber is offline
Reply With Quote
View Public Profile
 
Old 04-24-2006, 08:17 PM Re: Search DB Problem
ChancesAre's Avatar
Skilled Talker

Posts: 84
Trades: 0
I see 2 ELSE there
ChancesAre is offline
Reply With Quote
View Public Profile
 
Old 04-27-2006, 11:42 PM Re: Search DB Problem
Novice Talker

Posts: 10
Trades: 0
Thanks for the help and sorry for the delayed response. Finals Anyway I got the errors fixed. I removed the extra echo statement and a couple other ones but now I get no output. I have entered in data I know is in the db to test it and I get nothing displayed. Any ideas would be helpful.
avis is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Search DB Problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13190 seconds with 12 queries