Jump to content

[!!!] This stupid bug is driving me crazy....


phpakos

Recommended Posts

i have setup a database with this table structure:

 

$query = "CREATE TABLE entry ( entryID int NOT NULL AUTO_INCREMENT,

PRIMARY KEY(entryID),

URL varchar(4096),

name varchar(1024),

kw tinytext )";

 

I have filled in the database with data:

 

entryID

1

URL

http://www.bmwdealer.info/kwngat/9 Hite 6 Princesh...

name

02-Poni - Thashethemet-9 Hite 6 Princesha

kw

9

 

(data copied from a sample row from phpmyAdmin).

 

 

Now this is my code:

 

$term = '1';

$term2 = '9';

$query = "SELECT * FROM entry WHERE entryID = '$term' AND kw='$term2' ";

$result = mysql_query($query);

$numresults = mysql_num_rows($result);

echo $numresults."<br>";

if(!$result)

{

die('Invalid query: ' . mysql_error());

}

else

{ //something was found..

while($row = mysql_fetch_array($result))

{

echo "-Entry-<br>";

echo $row['entryID']."<br>";

echo $row['URL']."<br>";

echo $row['name']."<br>";

echo $row['kw']."<br>";

 

}

};

 

 

THIS CODE DOESNT GIVE ANY RESULTS AND THE PROBLEM APPEARS TO BE THE: AND kw='$term2' part of the QUERY because if i remove it, it DOES produce the expected result.

 

Any idea what is going on? Why is it not matching the kw field?

 

Please help me out with this

 

thanks alot, in advance..

Link to comment
https://forums.phpfreaks.com/topic/57845-this-stupid-bug-is-driving-me-crazy/
Share on other sites

wildteen: it also contains text... it can be whatever...

 

i used this code:

 

$b = fgets($fh);

$a = substr($b,0,-1);

 

the second line removes the character which was causing the bug..

 

 

any idea what that character is? I tried removing specifically the newline character but that wouldnt work.. so i figured it is another type of character...

 

the $b variable is loaded from a file of this format:

...

7

9

Hite

6

Princesha

....

You should use trim which will remove whitespace characters at the beginning and end of a string. Depending on the OS the file was created on it could have \r\n or \n or \r whitespace characters for newlines using trim removes all possibilities giving you clean string/line

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.