Find a record using the value of a cookie

Asked

Viewed 49 times

0

I can’t find a value in the database by a select using as reference a variable from a cookie:

$query = "SELECT * FROM carrinho WHERE dono = '$dono'";

However, if you search using the variable text,

$query = "SELECT * FROM carrinho WHERE dono = 'd2466de8-ccde-4939-f756-bf427f'";

the desired values are found.

The variable $dono comes from a cookie: $dono = $_COOKIE["id_user"];

And if so echo the variable appears the same text (d2466de8-ccde-4939-f756-bf427f)

  • are you sure if into your browser the cookie exist.

  • We are at [en.so], please translate your question.

  • yes the cookie exist if i write echo $_COOKIE["id_user"]; its says d2466de8-ccde-4939-f756-bf427f'

  • Echo the $query variable, copy and paste it into the bank to test. See if your php code is processing this $query variable correctly, connects to the database, executes the query and brings the resultset. Iterate by the resultset printing the values on the screen.

  • @Ricardoroque the value parentheses was Voce that added or are in the variable?

  • @Omni not the parentheses ' ' does not leave the variable but even taking does not correct

  • I don’t understand why : "SELECT * FROM carrinho WHERE dono LIKE $dono" be different from: "SELECT * FROM carrinho WHERE dono LIKE 'd2466de8-ccde-4939-f756-bf427f'" when giving echo from $dono the result is d2466de8-ccde-4939-f756-bf427f

  • Is there any way to put your complete database code? Give a var_dump($dono) and put here exactly the result without changing anything.

  • var_dump result was: string(36) "d2466de8-ccde-4939-f756-bf427fc4f8fa"

  • @Anderson Carlos Woss, did he set the cookie to be true across the domain

  • @Ricardoroque put the full code of the script then;

  • the script itself is: http://prntscr.com/feoav3 the creation of the cookie is setcookie("id_user", $id, time() + (10 * 365 * 24 * 60 * 60 * 60), "/");

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.