0

I have lost 4 hours on this thing so far, and it's very very strange. I have the following simple select:

SELECT pl.id_product, pl.link_rewrite as `product_link` 
FROM ps_product_lang pl 
WHERE UPPER(pl.`name`) = UPPER('HAVOLINE EXTRA SAE 10W-40')

My PHP code is the following:

$strsqlGruppe = 'SELECT pl.id_product, pl.link_rewrite as `product_link`
    FROM ps_product_lang pl 
    WHERE UPPER(pl.`name`) = UPPER(\''.$name.'\') ';

echo('<pre>'.$strsqlGruppe.'</pre>');
$ressqlGruppe = mysqli_query($db_conn, $strsqlGruppe);
while ($row = mysqli_fetch_array($ressqlGruppe))
{
    $url = $row['product_link'];
    return $url;
}

There is one record that match for this $name and it does not given as result. I have tried to change the WHERE clause with "WHERE id_product=199" and it works like that. So the problem is with the WHERE clause: UPPER(pl.name) = UPPER('HAVOLINE EXTRA SAE 10W-40') . I have tried even STRCMP too but no result. What am I doing wrong?

Here is the phpMyAdmin screenshot with the result: enter image description here

Ervin
  • 2,374
  • 4
  • 30
  • 44
  • So if you copy the text from `echo('
    '.$strsqlGruppe.'
    ');` (without the `
    `s) and paste it in the query part of phpMyAdmin it works?
    – texelate Feb 15 '17 at 10:25
  • Also, one thing to check is that you are connecting using the same charset that phpMyAdmin is using (usually utf-8). – texelate Feb 15 '17 at 10:27
  • check for any errors using mysqli_error($db_conn) – undefined_variable Feb 15 '17 at 10:27
  • exactly, it works, I'm adding a screenshot from phpMyAdmin too. – Ervin Feb 15 '17 at 10:27
  • just tested `mysqli_error($db_conn)` is empty, so no error in the mysql query. No error on connection either. – Ervin Feb 15 '17 at 10:30
  • have put `header('Content-Type: text/html; charset=utf-8');` to use the same charset as in phpMyAdmin, but I have no special characters in this string so thats not the problem, thanks anyway for @texelate – Ervin Feb 15 '17 at 10:32
  • is your connection working? do you get any error reported? it is different to retrieve 0 results on a well formed query or to get 0 results because the query fails – Lelio Faieta Feb 15 '17 at 10:33
  • Yes @LelioFaieta I've checked it and connection is fine, and if I change the where clause to select directly the item after id like `WHERE id_product=199` it gives the result properly. – Ervin Feb 15 '17 at 10:35
  • Enable error reporting on the final query and see what it returns – Lelio Faieta Feb 15 '17 at 10:38
  • 2
    You can also try to echo the md5 of UPPER($name) and the md5 of UPPER(name) in the mySQL database, by that you can check if there is some strange encoding issue or maybe hidden character. – faulix90 Feb 15 '17 at 10:53
  • @faulix90 and to all other: thank you for your time. I have found the problem. faulix90's comment would anyway drive me to the same check I have made before: I have recopied from phpmyadmin and checked if it works. Yes, it is. So I have compared the two queries in the HTML source code. I have discovered that the variable $name had a closing `` tag on the end, which one I have not noticed in the front. Thanks for your time again! – Ervin Feb 15 '17 at 11:00
  • It's always the simplest errors that take the longest to debug! – texelate Feb 15 '17 at 14:01

0 Answers0