SQL and PHP brief explain -


$id=$_get['previd']; $sql = "select * pro prid=".$id; 

i new php. can explain happens here?

  • this taking value of (url) passed variable "previd". http://example.com/page.php?previd=123 set previd 123.
  • next sets variable $id 123.
  • next $sql gets set select * pro prid=123
  • next nefarious person can go http://example.com/page.php?previd=;drop table pro , database has been deleted.

this why people use sanitization , prepared statements.

// pdo + mysql $pdo = new pdo('mysql:host=example.com;dbname=database', 'user', 'password'); $statement = $pdo->query("select some_field some_table"); $row = $statement->fetch(pdo::fetch_assoc); echo htmlentities($row['some_field']); 

more info


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -