Hey everyone, I have created a PHP web application that allows people of different permissions to do certain things such as read-only, add, update, or delete. That works pefectly. However, it came across my mind that I have not done anything to prevent against SQL injection or XSS attacks. I have little to no knowledge on how to do that. I'll show what I have and maybe a little guidance can help me learn how to do some type of hardening on my tables.
<?php
//connects to the Database
include_once("sqlConnect.php");
//Checks the previous page for the choice selected from the Dropdown menu
if(isset($_POST['currentUser']))
{
$currentUser = $_POST['currentUser'];
$sql5 = "SELECT * FROM engineers WHERE UserID='$currentUser'";
$result3 = mysqli_query($conn, $sql5);
$row3 = mysqli_fetch_array($result3);
$Access = $row3["AccessCode"];
if ($Access <= 5)
{
if(isset($_POST['engineers']))
{
$UserID = $_POST['engineers'];
//SQL command to pull information from the table where Sales Engineers are
$sql = "SELECT * FROM engineers WHERE UserID='$UserID'";
//The result is saved here
$result = mysqli_query($conn, $sql);
//Will fetch the information
//Slightly redundant since we will only be selecting only one
//entry at a time
while($row = mysqli_fetch_array($result))
{
$EmployeeID = $row["EmployeeID"];
$FirstName = $row["FirstName"];
$LastName = $row["LastName"];
$Extension = $row["Extension"];
$Telephone = $row["Telephone"];
$Email = $row["Email"];
$PPhone = $row["PersonalPhone"];
$MPhone = $row["Mobile"];
$TeleAgent = $row["TelephoneAgent"];
$Department = $row["Department"];
$Access = $row["AccessCode"];
$UserID = $row["UserID"];
}
}
}
else
{
echo "<script> alert('You do not have permission to edit');
window.history.back();
</script>";
}
}
This is just a snippet of what I have. Pretty much, I will have a page that will add and I will also have another page to help delete. Same kind of thing but for different queries. Does anyone know what I can do to help make it harder to do SQL injection or XSS? Please don't give me code unless it's something that is really obvious that I should be doing. I want to learn, so a snippet here or there or a good article that can help me will be better for me. Thank you! By the way, I tried looking this up on google but can't really understand what the person who wrote the article was doing.