Menu

Get ID key from database-new info submitted

Help
jsherk
2007-06-02
2013-06-03
  • jsherk

    jsherk - 2007-06-02

    Does anybody out there with php & mysql experience know how to retrieve the unique id key that is created when a new entry (new row) is inserted into a table? I have limited php experience... I usually have to copy and paste code to things to work for me!!!

    I was looking thru the process.php code, and here is the code that puts the new entry (new row) into the database:

    $link = mysql_connect("localhost","myusername","mypassword");
    mysql_select_db("mydatabase",$link);
    $query="insert into mytable (info1,info2) values ('".$info1."','".$info2."')";
    mysql_query($query);

    The ID field is unique, and is automatically generated and auto-incremented everytime a new row is inserted into the table. Is there a way for this query function to also return the unique ID key that is generated in mytable? This will be a handy way to give the person who submitted the form a "Ticket#" that is unique to them.

    Thanks

     
    • TNTEverett

      TNTEverett - 2007-06-02

      This only remains unique if nothing is ever deleted.  You are better off creating a unique ID of your own.  In any case the phpFormgenerator admin retreives the ID number from the SQL db.  If you have the generator, create a form with SQL and have a look at the data retrieved with the admin.  You will see that on or about line 273 the data extractions starts at column 1.  Change this to start at 0 and the ID field can be displayed. 

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.