need to generate a unique id on submit ,in php form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • satyasampan
    New Member
    • Aug 2012
    • 9

    need to generate a unique id on submit ,in php form

    <?php
    $con = mysql_connect(" localhost","roo t","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db ("tutorial", $con);
    if($_REQUEST["submit"]=="submit")
    {
    $sql="INSERT INTO details ( Name, Surname, father, Gender, Martialstatus, Qualification, specification, Aggregate, Address, City, State,Pincode, PassportId, Mobile, EmailId)
    VALUES
    ('$_POST[Name]','$_POST[Surname]','$_POST[father]','$_POST[Gender]','$_POST[Martialstatus]','$_POST[Qualification]','$_POST[specification]','$_POST[Aggregate]','$_POST[Address]''$_POST[City]','$_POST[State]','$_POST[Pincode]','$_POST[PassportId]','$_POST[Mobile]','$_POST[EmailId]')";

    if (!mysql_query($ sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    }

    mysql_close($co n);
    ?>


    in this table Id is primary key and set to auto increment.


    a php form was created to insert the data.. and on submit from that form a unique code must be generated and it should go into Id column in the table...
    i think a function is needed ,can anyone help me in writing that function...plea se
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    If you have set your key field (id) to autoinc, then you don't have to do anything to generate the next value. The insert function will automatically add the next value to that field/column in your table.

    Comment

    • AyakaNamase09
      New Member
      • Sep 2012
      • 3

      #3
      if you want a value of like this 0001 and auto increment you can use the str_pad

      Comment

      Working...