Search the Community
Showing results for tags 'sql injections'.
-
Hi guys I've been working on a project for a while now, after getting everything functional so far, i decided its time to start locking the system down, and my first task is SQL injection prevention I really am having a hard time understand the whole sql injection thing, im pretty sure it where someone can manipulate the query so they can steal information from the Database? I followed a guide but i want to be sure for my first query, Is this SQL injection proof? <?php //This section is for adding a new user if (isset($_POST['NewUserSubmit'])){ //lets get the POST information $firstname = $_POST['FName']; $LastName = $_POST['LName']; $email = $_POST['EmailAddress']; $password = $_POST['Password']; $ContactNo = $_POST['ContactNumber']; $userLevel = $_POST['userLevel']; $userName = $firstname.".".$LastName; //change the password to MD5 $password = md5($password); // okay lets see if the user exists $selectUserName = "SELECT * FROM MC_users WHERE username='".$userName."'"; $selectResult = $pdo->prepare($selectUserName); $selectResult->execute(); //is this username already exists tell them! if ($selectResult->rowCount() > 0){ echo "<div class='alert alert-danger fade in'><strong> This user Already Exists please try a different user First and Last Name</strong><button class='close' data-dismiss='alert' aria-label='dismiss'</button>dismiss</div>"; } else {//else create the user // This worked so lets place the variables into the pdo query using an array $insertUserQuery = "INSERT INTO MC_users (firstname,lastname,username,secret,userLevel,email,contact) VALUES (:firstname,:LastName,:userName,:password,:userLevel,:email,:ContactNo)"; $Result = $pdo->prepare($insertUserQuery); if ($Result->execute(array(':firstname'=>$firstname, ':LastName'=>$LastName, ':userName'=>$userName, ':password'=>$password, ':userLevel'=>$userLevel, ':email'=>$email, ':ContactNo'=>$ContactNo ))){ echo "<div class='alert alert-success fade in'><strong>User ".$userName." has been created</strong><button class='close' data-dismiss='alert' aria-label='dismiss'</button>dismiss</div>"; } } } ?> any help is greatly appreciated And i thank everyone in advance for your help. Mooseh Man