Hello. Page gets id GET

$id = intval($_GET['itemid']); 

This $ id in some pieces of code is visible in others is not visible. There are no functions on the page. Before the announcement, tried to do global, still not visible in some places. I read the manual and other sources, there is no reason for invisibility. For example, this simplest command is not executed:

 if($_POST['deleteitem']){ pg_query($dbconnect,"DELETE FROM items WHERE id = '$id'"); } 

Closed due to the fact that off-topic participants Dmitriy Simushev , cheops , pavel , aleksandr barakin , user194374 Aug 10 '16 at 8:18 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Dmitriy Simushev, cheops, pavel, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • write a detailed code. where it is visible and where it is not - HELO WORD

1 answer 1

In single quotes, the variable must be included as follows: {$id} otherwise will not be processed. Read about the difference "and" in the documentation for php.

Better yet, bring the variable out of the string (string), for example:

 pg_query($dbconnect,"DELETE FROM items WHERE id = '".$id."'"); 
  • HELO WORD For example, after such a request, I display the product on the page: $ pic_query = pg_query ("SELECT * FROM items WHERE id = '$ id'"); $ pic_result = pg_fetch_assoc ($ pic_query); - recklessly
  • I have already tried it for everyone, and so ''. $ Id. "'And so {$ id} - rebukes
  • var_dump ($ id); before requesting? - iosp
  • iosp var_dump shows int310 - recklessly
  • 3
    @iosp in the TS variable is in double quotes, if you have not noticed ... single quotes inside double quotes are not considered ... in a query in the database it would be framed just in quotes - Alexey Shimansky