SQL injection happens when user input is pasted directly into an SQL string. An attacker can type SQL code instead of normal data.
Unsafe code (PHP):
$sql = "SELECT * FROM Users WHERE Name = '" . $_GET['name'] . "'";
If someone enters ' OR '1'='1, the query becomes WHERE Name = '' OR '1'='1', which returns every user.
The fix: prepared statements
Send the query and the values separately, so input is always treated as data:
$stmt = $pdo->prepare("SELECT * FROM Users WHERE Name = ?");
$stmt->execute([$name]);
Frameworks such as Laravel (Eloquent), Django and Node ORMs use prepared statements for you.