iamliam

Basic SQL Injection Prevention

Sep 11th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.36 KB | None | 0 0
  1. <?php
  2.  
  3. // Connection String here
  4. $con = new mysqli("localhost", "root", "", "database"0;
  5.  
  6. // For example, you have an ID value in your $_GET
  7. $id = $con->real_escape_string($_GET['id']);
  8.  
  9. // Your Query
  10. $con->query("SELECT * FROM users WHERE id = $id"); // You use the variable $id where the content is already escaped instead of calling $_GET['id'] directly
Advertisement
Add Comment
Please, Sign In to add comment