First of all, if you are worried about SQL-Injection then you should filter any input from your user and validate it.
The best protection is done with prepared statements. Like this:
<?php
/** Open DB-Connection */
$pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$firstname = "John";
$lastname = "Smith";
$email = "info@youremail.com";
/** Your SQL-Statement */
$statement = $pdo->prepare("SELECT * FROM users WHERE firstname = :firstname OR lastname = :lastname OR email = :email");
/** Fills the parameter */
$statement->execute(array('firstname' => $firstname, 'lastname' => $lastname, 'email' => $email));
?>
Your attempt to replace the *
will not work. C-style comments are vulnerable to exploits. If a hacker will send "*" as a UTF-encoded sign for example, he might be sending (encoded) this:
(USERNAME 1ST LINE, PASSWORD 2ND LINE).
attacker', 1, /*
*/'pwd