如何使用php自动增加值

I have a database table registration(id,firstname,comment,reg_id)

iam fill the form and values are insert into database (firstname comment) ,i want to insert reg_id automatically.

id  firstname       comment        reg_id
1       Alexy         tfhgfnjh     R20123       
2       Thomas        fdghfgh      R20124  
3       chako         cgjkjhl      R20125       
4       Thomasxc       cgjkjhl     R20126          
5       Thomaseg       fdghgh      R20127      
6       Thomasm        fsgdfgbd    R20128  

but its not work ,reg_id value was not increment properly.

Code From Comment.

if($checksql>$reg_id){ 
  $checksql1=mysql_query("select reg_id from registration where id='$rid'"); 
  $r=mysql_fetch_array($cheksql1); $rgid=$r['reg_id']; 
  $reg_id1= $rgid+1; 
  $regid=mysql_query("update registration set reg_id='$reg_id1' where id='$rid'");  
}

how to solve my problem?

if ($checksql > $reg_id) {
    $checksql1 = mysql_query("select reg_id from registration where id='$rid'");
    $r = mysql_fetch_array($cheksql1);
    $rgid = $r['reg_id'];
    $reg_id1 = 'R' . (substr($rgid, 1, strlen($rgid)) + 1);
    $regid = mysql_query("update registration set reg_id='$reg_id1' where id='$rid'");
}

You can use substr() to get the numbers part of your id. Increment it by 1 and concatenate it with the leading "R". (or if it doesn't have to be an "R" but could be something else. If there can be multiple letters you would need to count them first)

$reg_id1 = substr($rgid, 0, 1) . (substr($rgid, 1, strlen($rgid)) + 1);

Also see this: Why shouldn't I use mysql_* functions in PHP?

Here you get the last executed reg_id, then convert into the substring.

$last_regid=mysql_query("SELECT reg_id FROM  registration ORDER BY id DESC LIMIT 0 , 1");
$row=mysql_fetch_assoc($last_regid);
$last_register=$row['reg_id'];
$substring = substr($last_register, 1);
$substring++;