表单提交后生成引用ID

I am trying to generate a reference id like this CTS-P 0 then CTS-P 1 each time a user submits a form and it gets inserted.

what i have came up with is inserting CTS-P 0 to database as i submit.but the problem is its not incrementing CTS-P 0 to CTS-P 1 after i submit again.

i tried to use mysql_insert_id() here is what i have done so far.this is the smallest thing but i could not solve. please have a look

    <?php 
$con=mysql_connect("localhost","root","");
mysql_select_db("dbname",$con);
$genid="";

if(isset($_POST['submit'])) {   
$frstname=$_POST["frstname"];   

$genid=mysql_insert_id();
$genid .=count($genid);
//echo $genid;

for($i=0; $i<$genid; $i++) {

$sql = "INSERT INTO tblname (`namecol`,`refidcol`) VALUES ('$frstname','CTS-P $genid[$i]')";
$result = mysql_query($sql);
}}
    ?>

//here is the form
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="generate" >

First Name<input type="text"  name="frstname" />
<input type="submit" name="submit" value="Submit" />
</form>

it is inserting it in my refid column as CTS-P 0 but not incrementing from next time i submit.i know its very noobish but i am stuck.

<?php 
    $con=mysql_connect("localhost","root","");
    mysql_select_db("dbname",$con);

    if(isset($_POST['submit'])) {   
        $frstname=$_POST["frstname"];   

        $sql = "SELECT * FROM tblname";
        $genid = mysql_query($sql, $con);
        $genid = mysql_num_rows($genid);

        //Since you're using "0" as your first number, I decided to comment this out, if not, uncomment it
        //$genid++;

        $sql = "INSERT INTO tblname (`namecol`,`refidcol`) VALUES ('$frstname','CTS-P $genid')";
        $result = mysql_query($sql);
    }
?>