, , , script.
( echo, , ?)
SQL , , mysql - .
: http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
SQL ( ?), mysql . , .
:
$mysqli = new mysqli('where your server is', 'my_user', 'my_password', 'world');
$stmt = $mysqli->prepare( "INSERT INTO Entries (myoption1) VALUES (?)" );
$stmt->bind_param( "s", $POST['myselectbox'] );
$stmt->execute()
, , .
SQL Injection
, , , SQL-.
, , , .
SQL Injection - , - SQL, "" SQL .
, :
$sql = "INSERT INTO Entries (myoption1) VALUES ('". $_POST['myselectbox'] ."')";
( ) - myoption1.
SQL:
INSERT INTO Entries (myoption1) VALUES ('myoption1');
- , '='' OR '1'='1
SQL:
INSERT INTO Entries (myoption1) VALUES (''='' OR '1'='1');
() .
, , '=')'; DROP TABLE Entries WHERE (''='
SQL:
INSERT INTO Entries (myoption1) VALUES (''=''); DROP TABLE Entries WHERE (''='');
Simply put, but using prepared statements, you tell mysql that what you are sending is a literal string that will be used as a parameter. It can never be seen as part of the statement itself, and therefore the foregoing is simply impossible.
Much safer.
I hope this becomes clearer. If you need more information, I suggest you study it yourself ...
source
share