Ok I think I might know what you are looking for from me. the problem is I do not know the code that I need to perform the function I want to be performed. I'm going to ry explain again what I am looking for by breaking it up into pieces and then I will include a small part of the code where I would think the function will occur.
1. I have a Database which I will refer to as DB for the example
2. In my DB I have two tables, namely USERINFO and FORM1
3. The user logs into the site a session is set and the user is authenticated with the two pieces of code below:
<?php
session_start();
if(!isset($_SESSION['user'])){
// the user is not logged in so let them login
?><?php
session_start();
include "mysql.php";
$_POST['username'] = addslashes($_POST['username']); // protects against SQL injection
$_POST['password'] = addslashes($_POST['password']); // same ^^
$password = ($_POST['password']); // encrypt the password
$userrow = mysql_query("SELECT * FROM `userinfo` "
. "WHERE `username` = '" . $_POST['username'] . "'"
. " AND `password` = '" . $password . "';",$mysql);
if(mysql_num_rows($userrow) != "1"){
// no rows found, wrong password or username
echo "<font color='red' face='Tahoma' size='2'><b>Please verify the username and/or password entered!</b></font>";
include "login.php";
} else {
// 1 row found exactly, we have the user!
$_SESSION['user'] = $_POST['username'];
header("Location: home.php");
}
?>4. Oce the user is logged in the will complete the form and submit the information. When submitting the form information I would like the update code that updates the FORM1 table to also gather information from the USERINFO table, i.e the auto incremeted ID which serves as a unique identifier. This info along with the info submitted via the form needs to be populated into FORM1 table. Below is my current code for the form, but it is not populating the ID from the USERINFO table
$sql="INSERT INTO FORM1
(id
,customer_name
,customer_email_address
,case_number
,msisdn
,call_reason
,province
,comments
)
VALUES
([b]NOT SURE HOW TO GATHER THIS PART FROM MY USERINFO TABLE[/b]
'$_POST[customer_name]'
,'$_POST[customer_email_address]'
,'$_POST[case_number]'
,'$_POST[msisdn]'
,'$_POST[call_reason]'
,'$_POST[province]'
,'$_POST[comments]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<b><font color='red' face='segoe' size='2'>1 record added</b></font>";
include "technical_support_tracker.php";
mysql_close($con)
?> I have search everywhere for a solution to this, but have had no luck, please can you try and assist me here as this is quite urgent. Thanks for you patience with me on this. I am still very new to PHP and everything I have done here I have taught myself using google.
I almost forgot tis part, hre is my table structure of the two tables as well as the server info:
-- phpMyAdmin SQL Dump -- version 3.3.2--
http://www.phpmyadmin.netGeneration Time: Jun 14, 2010 at 07:58 AM -- Server version: 5.1.46
--
PHP Version: 5.3.2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
Table structure for table `USERINFO`
CREATE TABLE IF NOT EXISTS `userinfo` (`id` mediumint(50) NOT NULL AUTO_INCREMENT
, `username` varchar(60) NOT NULL
, `password` varchar(60) NOT NULL
, `name` text NOT NULL
, `surname` text NOT NULL
, `email_address` varchar(100) NOT NULL
, `department` varchar(100) NOT NULL
, PRIMARY KEY (`id`)
, UNIQUE KEY `id` (`id`,`username`,`email_address`)
, UNIQUE KEY `e-mail` (`email_address`)
, UNIQUE KEY `username` (`username`)
Table structure for table `FORM1`
CREATE TABLE IF NOT EXISTS `FORM1`
( `id` varchar(50) NOT NULL
, `date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
, `customer_name` varchar(100) NOT NULL
, `customer_email_address` varchar(100) NOT NULL
, `case_number` int(50) NOT NULL
, `msisdn` int(10) NOT NULL
, `call_reason` varchar(50) NOT NULL
, `province` varchar(50) DEFAULT NULL
, `comments` varchar(2500) DEFAULT NULL)