![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Regular Coder ![]() Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
Auto Fill Form Inputs
Lets say I have a drop down menu were the options are MySQL query results. I want when I choose an option for the form to display that person's information automatically that is already stored in the DB. I think I might have to have some JavaScript to make this work.
I have the drop down menu that list the person's name from the MySQL query. Next to the drop down menu I have 3 text boxes...user's name, user's sex, user's age. I want 3 text boxes to display the information that is already in the Database when I choose the user I want to see. I have the DB table that houses users information already with the information already entered. Once I click user 2 I want that user 2's name, sex, & age to be displayed in those 3 text boxes that I already have. Then if I choose user 10 I want user 10's information to populate in those 3 text boxes. I hope I am making sense... |
|
|
|
|
|
PM User | #2 |
|
Senior Coder ![]() Join Date: Mar 2003
Location: Atlanta
Posts: 1,037
Thanks: 14
Thanked 30 Times in 28 Posts
![]() |
I'm not sure that this is the best way but if you were to query the DB and retrieve all the values on the page for each user and place them in an array.
You could then set the textbox values to be the arrays index. You can use javascript to scroll through the array. I like the innerText or innerHTML property personally. http://msdn.microsoft.com/library/de.../innerhtml.asp And as I said..I'm not sure if this is the best way to do this.
__________________
Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough. |
|
|
|
|
|
PM User | #3 |
|
Senior Coder ![]() Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
You can use something like this
http://computer-helpforum.com/php/co...ulate_form.php PHP Code:
When submitted the variable is used in the second query and that is used to populate the textfields. |
|
|
|
|
|
PM User | #4 |
|
Regular Coder ![]() Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
Thanks...That is exactly what I want. I have changed the things that I needed to. It isn't working. My code is below.
This are the column name for the 3 text boxes that I want to display Customers' E-Mail : customers_email Customer's Id #: customers_id Customer's Name: customers_username I deleted lines 5 & 15 since I have those lines in my cdb.php file. Also the , $db on lines 7 & 17 since I kept getting error that sd Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\phpdev\www\templates\template 1\cp\add.php PHP Code:
|
|
|
|
|
|
PM User | #5 |
|
Senior Coder ![]() Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
mysql_query requires the mysql_pconnect variable in this setup.
PHP Code:
PHP Code:
Example code: PHP Code:
|
|
|
|
|
|
PM User | #6 |
|
Regular Coder ![]() Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
In that required cdb.php I have the pconnect...I tried it the way you had it just changing the colum names to match my db...It still isn't working.
PHP Code:
|
|
|
|
|
|
PM User | #8 |
|
Regular Coder ![]() Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
The text boxes aren't getting field. I choose an e-mail in the drop down menu...the page acts likes it is automatically reloaded the page once I click the option in the menu but nothing appears in the text boxes.
|
|
|
|
|
|
PM User | #9 |
|
Senior Coder ![]() Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
You would have to post a link to the page with the source code and database structure.
Personally, I think you should just look through the code and put in error checks and echos to make sure the submitted data is what it is supposed to be. |
|
|
|
|
|
PM User | #11 |
|
Regular Coder ![]() Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
http://www.hostwithgold.com/testing/add.php
There is the link to that page & here is the source code...the add.php file PHP Code:
Code:
CREATE TABLE `customers` ( `customers_id` int(11) NOT NULL auto_increment, `customers_firstname` varchar(32) NOT NULL default '', `customers_lastname` varchar(32) NOT NULL default '', `customers_email` varchar(96) NOT NULL default '', `customers_phone` varchar(32) NOT NULL default '', `customers_phone2` varchar(32) NOT NULL default '', `customers_street_address` varchar(64) NOT NULL default '', `customers_city` varchar(64) NOT NULL default '', `customers_postcode` varchar(64) NOT NULL default '', `customers_state` varchar(64) NOT NULL default '', `customers_country` varchar(64) NOT NULL default '', `customers_fax` varchar(32) default NULL, `customers_username` varchar(30) NOT NULL default '', `customers_password` varchar(40) NOT NULL default '', `customers_newsletter` char(1) default NULL, `customers_ip` varchar(32) NOT NULL default '', `customers_date_of_last_logon` datetime default NULL, `customers_number_of_logons` int(5) default NULL, `customers_date_account_created` datetime default NULL, `customers_date_account_last_modified` datetime default NULL, PRIMARY KEY (`customers_id`) |
|
|
|
|
|
PM User | #12 |
|
Regular Coder ![]() Join Date: Jan 2003
Posts: 863
Thanks: 4
Thanked 8 Times in 8 Posts
![]() |
It appears to be a problem with your second SQL query. The value of $colname_chosen_seminar will either be -1 or an email address. And you are searching your db table for customers_id which is an int.
$query_chosen_seminar = sprintf("SELECT * FROM customers WHERE customers_id = %s", $colname_chosen_seminar); Do an echo of your sql statement and make sure it looks how you want it. Test it in phpmyadmin or by passing it statically to your db. |
|
|
|
|
|
PM User | #13 |
|
Regular Coder ![]() Join Date: Dec 2005
Posts: 346
Thanks: 1
Thanked 0 Times in 0 Posts
![]() |
I am not too good at this error testing with echo. I am not all that great with php. I tried this code below with the echo for errors. I am not sure if this is how you test for errors or not so if it isn't then could you say how to test it for error or give link to a tutorial on how to test for errors with echo's? I have the echo's echoing First query error or Second query error for the 1st & 2nd queries, but I put a number 1,2,3, & 4 in the echo text so that I could tell which step the error was in.
Also on the link that degsy provided once you choose an drop down option the page displays the text boxes with the info, but also the option that you chose was still chosen...you could see the option you chose without clicking to drop the menu down. With the code below I got this showing: First query OK 1 First query OK 2 First query OK 3 First query OK 4 Second query OK 1 Second query OK 2 Second query error 3 Second query error 4 PHP Code:
|
|
|
|
|
|
PM User | #14 |
|
Senior Coder ![]() Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Your select name is attend
PHP Code:
PHP Code:
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|