Jump to content

Recommended Posts

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;

?>"

 

/>

 

 

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.