I just cannot get this solved and after way too much time on this, I'm here for help.

Here's my code snippet:

while ($row = mysql_fetch_assoc($result)) {
    $domain = $row["domain"];
    $domainwww = "www.".$domain;
    //$domainwww = "www.google.com";
     $sql2 = "SELECT url_id, url 
	     FROM urls
             WHERE url='".$domainwww."'";

My problem is that my query $sql2 returns no rows when I have $domainwww set to:
$domainwww = "www.".$domain;
[when I echo $domainwww is prints just fine]

However if I comment that out to hard code the value of $domainwww like:
$domainwww = "www.google.com";

The query works just fine. What am I missing?

thank you. Jeff

Recommended Answers

All 3 Replies

hm, maybe in "www.".$domain you have space or other symbols. give me all code, maybe i am help you.

Echo $sql2 after line 7 and see if contains what you expected. If it is correct, it will work.

Thank you both for your help and time. Your comments helped me to see that i have a single character of trailing whitespace in the query which I couldn't immediately see when echoing $domainwww (why did I not check it in source code view!) The output from the query looks like

SELECT url_id, url FROM urls WHERE url='www.0-0.com '

where you can see there's a space at the end. I don't know if this space is coming from the database record, from the concatentation of the string to the variable, or the sql query but I should be able to figure out the culprit.

thank you again - jeff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.