I have two question
is the following code a good way of practicing against SQL injection ( it seems to work OK as an insert method)
How would in place this error message in the full example:
if (!mysqli_query($query,$link)) { die('Error: ' . mysqli_error()); }
here is the full example:
<?php
$link = mysqli_connect("localhost","root","", "runtracker");
if (!$link)
{
die('Could not connect: ' . mysqli_error());
}
$query="INSERT INTO userinfo (UserName) VALUES (?)";
if ($stmt = mysqli_prepare($link, $query)) {
// Lets create the variables
$name = $_POST['UserName'];
// Bind the variables and execute the query
mysqli_stmt_bind_param($stmt,"s", $name);
mysqli_stmt_execute($stmt);
// And now we close the statement
mysqli_stmt_close($stmt);
}
echo "1 record added";
mysqli_close($link);
?>