turpentyne Posted July 10, 2010 Share Posted July 10, 2010 Bear with me. I'm extremely new at this. I have a working form that submits data to one table. Then it redirects to a second form, to enter data for a second table. My challenge is that I need one of the fields in that table to match the auto_generated id field in the first table. The way I'm trying to do this, is by sending one unique entered variable from form1 to the header of form2, and then checking table1 for that variable to get the matching ID. This then will be part of form2 as a hidden field. currently I have it as a text field so I can see if it's working, but the text field is empty. Maybe somebody can spot what I've missed. or suggest a better way to do this... (var1 is the variable that I've passed from form one. I tested with just that information, and it did appear in the text box) Here is the code where the problem seems to be, in the hidden field on form2: <FORM action="form2.php" method="post">Enter your data </b> <input type="text" name="id" value=" <?php $var1 = $_GET['var1']; require ('this_is_my_database_connection.php'); $query = 'SELECT id FROM table WHERE second_field = $var1'; $result = @mysql_query ($query); echo $result; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/207383-connecting-two-forms-and-their-respective-tables/ Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2010 Share Posted July 10, 2010 mysql_insert_id() will return the auto-incremented index value for the last inserted record. You can then pass it via GET/POST/SESSION to the next form, for insert into the related table. Quote Link to comment https://forums.phpfreaks.com/topic/207383-connecting-two-forms-and-their-respective-tables/#findComment-1084246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.