Hello Guys...

I'm a novice in both php/mysql. I'm creating an application and have many problems with it.I need help with some of the areas.

First my application is a multiple forms based. The first page is that an admin logs into it by authenticating with mysql (This part I've completed). The admin goes to dashboard. Where on the top there is a link to add a new user through a HTML form (adduser.php).The admin fills in the new user's details(surname, forename,jobtitle, location,start date, end date.) and hits next--------now here comes my problem---- I have created a table in the database (users). I want the infos from the form to be inserted into this table and plus i want to retrieve the new use's ID as in a URL variable so when data insertion is completed in adduser.php (with URL showing the new user id on next page adduser2.php (in address bar adduser2.php=new users's id from database). On adduser2, a series of system applications icons are presented in the table. Each icon is basically a page/link for a system containing the system access rights required by the new user. When admin clicks on windows icon (on hovering win icon the admin should able to see windows.php?=userid -- since he retrieved it from the database on previous page) -- he is presented with a form, the admin fills in the form again and sends it. The datum is inserted into the database into windows table. This windows table has its own wind_id and win_uid, which is new user's id. After data insertion, the admin comes back to adduser2.php with the system icons. The admin can add as many as systems for the new user. All the systems have their own tables in the database and they are connected to users table through the user id key in each table. Now what my problem is that I do not really know how to retrieve new user id after 1st form submission as in a URL variable. I want to linkup the whole adduser.php , adduser2.php and systems forms together so I know a single user has this many system access under his name and the access right required by him and all the data is saved in the database tables with new user's id.

In simple words --- I do not know how to linkup the forms for a new user by his Id when his datum is added to mysql users table in first submission. I have been told that i can use mysql_insert_id(); but since im new to this all, im finding it really difficult to use and understand.

Please can someone guide me, using some examples. I am not asking for answers but am trying to learn by asking the experts. Please do bare in mind that I am a novice in both php/mysql so please use simple terms to explain.


I'm using codes something like this. Now, how to creative user id after submission. These are not the real form data or values in the original form. Im using this as a example.

<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$forename=$_POST['forename'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);

header("adduser2.php");
// close connection
mysql_close();
?>

Just make 22. header("adduser2.php?".mysql_insert_id());

But really if you can't figure that out from http://php.net/mysql_insert_id , I'm not sure what to tell you.

Personally I'd rather set a session variable with the userid.

Your post is kind of long and unwieldy, to get better response you need to be as concise as you can. Here's my goal, here's what I tried, here's what happened when I tried that. Something along those lines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.