I have a loop that is inserting new rows into my database. It is specifically designed to insert a specific number of rows with a unique value in the 'name' column.
while($rows_inserted < 100) {
// Create a random number
//Min & Max values for the random numbers
$min = 5001;
$max = 5100;
$number = rand($min,$max);
//Connect to the DB using $con details & execute query
mysqli_query($con,"INSERT INTO cmssps_card_codes (id, parent_id, name, status) VALUES ('', '', '$number', '0')");
if (mysqli_affected_rows($con) === 1) {
$rows_inserted++; // update the counter
}
}
In this particular limited instance, I'm creating 100 "random" numbers between 5001 and 5100 so it's redundant in this instance but the random number is used in production instances - just to avoid confusion.
My problem is that this statement executes successfully, however only 87 odd rows are actually created. I then try running the code to insert a single instance of the previously excluded rows and it enters an endless loop - I can, however, create the row directly in the database. It's as if the PHP code recognises that the row has been created when in fact it hasn't.
Any ideas?
namehas auniqueconstraint on it?