- Where Developers Learn, Share, & Build Careers


I am trying to work with PDO for the first time and I want to know what I am doing, how safe is it I

, I'm also new to PHP.

I have a question that when a user passes my page, the page takes a variable using GET and then runs.

With PHP, I've always used mysql_real_escape to get my varietates sanitized.

Can anyone see security flaws with this?

// Get the person ID $ User ID = $ _GET ['userID']; // People $$ sql = "Select * Individuals with ID = $ userID"; $ Q = $ conn- & gt; Query ($ sql) or die ($ conn- & gt; error ()); While ($ r = $ q- & gt; Fetch (PDO :: FETCH_LAZY)) {echo '

Do not use the query, prepare:

$ userID = $ _GET ['userID']; $ Sql ​​= "People from WHOE ID =: userid"; $ Q = $ conn- & gt; Ready ($ sql) $ q- & gt; Execute (Arrays (': userid' = & gt; $ userID)); While ($ r = $ q- & gt; Fetch (PDO :: FETCH_ASSOC)) {echo '& lt; Div class = "mis-per" & gt; '; Echo '& lt; Span class = "date-submitted" & gt; . $ R ['date_submitted'] '& lt; / Span & gt; '; // more STUF echo & lt; / Div & gt; '; }

The SQL statement can include the zero or more named (: name) or question mark (?) Parameter markers, for which the actual value is replaced when the statement is executed .


Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -