Here's some example code:
$sql = "INSERT INTO Users (Firstname,Surname) VALUES ('$firstname', '$surname')";
$stmt = sqlsrv_query( $conn, $sql,array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if(!$stmt)
{
die('Yu feiru!');
}
There are 3 columns in the database; ID, firstname and surname. ID is an auto increment primary key. I also have firstname as a unique key. So, now that I've put this all into perspective, all explain my problem.
When my form is complete it goes to the page were the above code is executed. Now, initially this works, as it should, so now I'll have my first record in the table with ID as 1. Now, if I am to refresh this page it returns an error, this is obviously because I am inserting the same firstname, and since it's a unique key it won't work, so far so good.
Here's the problem, if I am now to return back to the form and submit it with new details, the new record displays an ID of 3. So the problem is here that every time I run the query, whether it is successful or not, it increments the ID. So before, if I were to refresh the page 5 time, then the new record would have had an ID of 7.
EDIT: Please note, as I have stated, this is just example code. I still haven't taken any precautions against SQL injections. Regardless of this, thank you very much for your recommendations.