942,520 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2032
  • PHP RSS
Jun 8th, 2010
0

Php/MYSQL form ...data insertion and user id retrivel

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $host="localhost"; // Host name
  4. $username=""; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="test"; // Database name
  7. $tbl_name="users"; // Table name
  8.  
  9. // Connect to server and select database.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. // Get values from form
  14. $forename=$_POST['forename'];
  15. $lastname=$_POST['lastname'];
  16. $email=$_POST['email'];
  17.  
  18. // Insert data into mysql
  19. $sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
  20. $result=mysql_query($sql);
  21.  
  22. header("adduser2.php");
  23. // close connection
  24. mysql_close();
  25. ?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zia zia is offline Offline
12 posts
since Jan 2010
Jun 8th, 2010
0
Re: Php/MYSQL form ...data insertion and user id retrivel
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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
amac44 is offline Offline
17 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: connect to database
Next Thread in PHP Forum Timeline: Database and Check box





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC