1

I tried doing this in PHP but I got 0 rows returned all the time. Then after some time searching around on StackOverflow, I saw a tip to try doing it in SQL first to see if the results are returned properly.

I tried to do it in SQL and it's returning an empty result set all the time, even tho the values are there.

SQL

SELECT * FROM `serials_table` WHERE `ser_key`='ABCD-EFGH-IJKL-MNOP'

PHP

$result = $link->query("SELECT * FROM serials_table WHERE ser_key='$key'");

Both are returning null value.

ser_key column is set to text type, coallition: utf8_unicode_ci, Null: No, Default: None

The serial key entry is in there and the column 'ser_key' exists as well as the table 'serials_table'. Also I directly copy-pasted the serial key from the table and placed it into the query to avoid any typos.

Did I make some errors with the table structure or something?

I have no idea what to do here, any help would be appreciated.

3
  • Try SELECT * FROM serials_table WHERE ser_key like '%ABCD-EFGH-IJKL-MNOP%' to see if it is a trim issue Commented Nov 20, 2013 at 15:19
  • Can you check if there are hidden spaces in the value field of column ser_key. For example; 'ABCD-EFGH-IJKL-MNOP ' Commented Nov 20, 2013 at 15:20
  • @juergend Yes it is working now. How can I avoid that issue from happening again? Also, could you post this as an answer so I can mark it as solved? Thank you very much! Commented Nov 20, 2013 at 15:23

2 Answers 2

1

When this works

SELECT * FROM serials_table WHERE ser_key like '%ABCD-EFGH-IJKL-MNOP%'

Then you have leading or trailing spaces in your data.

To revert that update your existing table data like this

update serials_table 
set ser_key = trim(ser_key)

After that check where you insert or update the ser_key. In that code segment check if you put only trimmed data in there.

Sign up to request clarification or add additional context in comments.

Comments

1

Try

SELECT * FROM `serials_table` WHERE TRIM(`ser_key`)='ABCD-EFGH-IJKL-MNOP'

Remove white spaces

UPDATE `serials_table` set `ser_key`= TRIM(`ser_key`);

1 Comment

I was about to say to TRIM the input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.