It seems to me you only need to change:
$rc = $row_count[0] + 1;
to:
$rc = $i + 1;
as $i
is the counter you are using for the images.
And just in case, the mysql_*
functions are deprecated and you have an sql injection problem. You'd better switch to PDO or mysqli and use prepared statements with bound variables.
Edit: To be able to get the next sequence number from the database, you have to store the images in the database, otherwise you will never get an increase in the number of images found.
Apart from that this method will fail: If you delete for example the 2nd image of 8, your count will give you 8 as the next available number and you will overwrite your number 8 which is actually your 7th image.
You need to store the sequence numbers in the database to make sure you don't overwrite anything.