So I have finished creating a database and I use php to insert data into it, I have been trying to do SQL injection attacks and other things to see if I am secure, but since I am no expert I was hoping to check that what I have done is secure and the correct way to go about.
I have this(names/variables have been modified) form and when the submit button is pressed, the function insert() runs
<form action="" method="POST">
var1: <input type="text" name="var1"><br>
var2: <input type="text" name="var2"><br>
<input type="submit" value="Submit">
</form>
<php?
function insert() {
$connect = mysqli_connect("localhost","user","user","table");
$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
mysqli_query($connect, "INSERT INTO column_name (var1, var2) VALUES ( '$var1','$var2'); ");
}
?>
and I can't seem to inject my form which has var1 and var2 with this
$var2 = '): DROP TABLE test --and several variants of this
From looking around I have found that mysqli_query will only accept one query so that is why it is not working. Correct me if I am wrong.
my other idea was affecting the PHP script that is running, by injecting the form with this
$var2 = "'); "); mysqli_query($connect,"DROP TABLE test");//
Question: can this type of thing happen? where you can affect the PHP function through the $post method while it runs? I have looked around and can't find anything. Is that because it can't?
any research papers, articles, etc. that I can have a look at to help if what I am asking is obvious would be appreciated :)
EDIT: I will be adding prepared Statements to make this secure