Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Thanked 0 Times in 0 Posts

    Exclamation Pulling ID from MySQL and using as a hidden field

    I have a multi-page (multi-form) survey and want to make sure that each form can be connected to the others via some sort of ID.

    The login page asks for first, last name, username, newpassword, confirmed password, with the login form being processed by the following script:

    PHP Code:
    $database "mydb";
    $host "myhost.edu";


    mysql_select_db($database) or die( "Unable to select database");

    $query "INSERT INTO imoi_login_1 VALUES (null,'$fname','$lname','$usename','$userpw','$confpw')";

    $result mysql_query($query);
    if (!
    $result) {
    'Invalid query: ' mysql_error());
    "Responses have been saved";
    The "null" that is inserted into the table represents a placeholder for an ID variable that is added by MySQL.

    Is there any way to pull this ID number from the db and use it as a hidden field on subsequent forms? This is necessary so that I can match responses from one form (saved in one table of the db) with another set of responses by the same user (saved in a different table of the db).

    Thanks in advance to anyone who helps, and please include code if possible.

    Many thanks.


  2. #2
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Thanked 0 Times in 0 Posts
    If it's all in the same db, just in different tables, just query the table that has the ID and assign the value to a variable. That is provided that you have a way of targetting the desired row in the database table.

    <input type="hidden" name="id" value"<?php print $IDvalue; ?>" />

    You may have to elaborate a bit on this scenario.

    Is the ID that will be added taken from a database of current users?
    In other words what does the ID have to be matched with that the user is inputting?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts