Single and double quotes giving error in PHP

Asked

Viewed 39 times

1

I have the following code:

$db -> setQuery("
INSERT INTO sir_ter_historico (idcorretor,data,alteracao)
VALUES ($id, '$data', '$_POST['form']['numero']');
");
$db->execute();

Only it’s wrong, because of the simple quotation marks on the '$_POST['form']['numero']'.

How can I fix this?

  • You can put between { }, for example: ($id, '$data', '{$_POST['form']['numero']}');

  • show, thank you!

  • 1

    This way is quite wrong to do, even putting {} not ideal, this one $db is what ???

  • @Virgilionovic if you’re talking about bindParams agree

  • That’s it @Guilhermenascimento but, as we do not know which variable is this $db the solution that the user expects always the fastest, and still receiving positive votes ... !!! incredible!

  • 1

    @Virgilionovic yes, these Frees upvotes are a huge problem in the community, most of whom vote like this don’t really have a reasonable knowledge of language, but I’m done fighting it. If the author edits the question and details the technologies maybe I’ll reopen it and let you know.

  • The question was about the security of inserting that or how to insert?

  • 1

    @Diegoschmidt the problem is how to insert, but if there are other problems, they must be cited, especially when it comes to application security. The purpose of the site is to discuss solutions to problems and, by chance, find the best solution, not deliver code that works, as welfare.

  • 1

    @Diegoschmidt independent of the question being about X or Y does not prevent us from indicating the ideal path, after all not because something works which is the ideal way to work. Assistentialism by assistentialism is only a major problem in the community, we should choose whenever possible to indicate the best "ways"

  • the $db is to make connection in the database. The "{" worked right

  • @Guilhermenascimento I just wanted to help from a quick force, I do not care to upvote, I really hope someone of a complete answer. Hugs.

  • @Diegoschmidt I understand perfectly, but we are just trying to point something out to you to improve on this issue ;)

  • @Leandromarzullo mas $db é um framework?

  • @Guilhermenascimento Yes, I apologize for what happened then. Thank you very much, hugs!

Show 9 more comments
No answers

Browser other questions tagged

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