Need to make a request to the database. For example:

$t=2` UPDATE schedule SET days='$_POST[days$t]' 

I think it’s clear on request what I'm trying to do. PHP gives an error when trying to execute. Is there any solution or is it worth resorting to the formation of a string before the request?

  • You will not believe, but nothing is clear - Anton Shchyrov
  • the solution may be: {$_POST[days$t]} . And it's easier to use prepared queries! - Alexey Shimansky
  • I would add to {$_POST["days$t"]} - teran
  • @ Alexey Shimansky And what are these days$t supposed to mean? - Anton Shchyrov
  • @AntonShchyrov In fact, the form passes data in the form of: $ _POST [time1], $ _POST [time2], and so on. I need to cycle through all these variables in some way so as not to produce code. I now think, can it somehow be done? - Danchyg1337

1 answer 1

If the query starts with a double quote, you can try this:

"UPDATE schedule SET days='".$_POST['days'.$t]."' WHERE .... request continuation

  • never build a query by concatenation. Use prepared queries - rjhdby
  • @rjhdby - thanks for the comment. Your answer made you think. I even asked a question on this topic. ru.stackoverflow.com/questions/761190/… - user277937
  • My comment was not about concatenation, but about creating an SQL query using it - rjhdby