473,791 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with populating an html form having more than one attribute

348 Contributor
Hello all,

I know it wouldn't be long before I was back. I have a dilemma and really have no idea where to look for an answer. I have two issues going on and I appoligize in advance if I'm wrong for putting them both into one single post.

My first question has to do with more of a design issue than anything else.

I have an html form that will be populated with data from a mysql database using php. My *insert* form has the basic name, address, phone number information. I am starting to wonder how my form will insert more than one phone number or even customer location.

Say a customer has 15 (Highly unlikley but for example sake) telephone numbers. My insert form needs to have a list of fields that will allow the person to enter those numbers. I'm looking for a clean design. Can someone give me any pointers as to how this should be done?

My tables are like this:

Expand|Select|Wrap|Line Numbers
  1. customer_table
  2. customer_ID
  3. customer_Name
  4.  
  5. customer_Location_table
  6. customer_Location_ID
  7. customer_ID
  8. address1
  9. address2
  10. city
  11. state
  12. zip
  13.  
  14. customer_Phone_table
  15. customer_phone_ID
  16. customer_Location_ID
  17. phone_Type
  18. area_Code
  19. phone_Number
  20.  
So if my insert form looks like this:
Expand|Select|Wrap|Line Numbers
  1. Customer Name
  2. Address1
  3. Address2
  4. City
  5. State
  6. Zip
  7. Phone Type
  8. Area Code
  9. Phone Number
  10.  
  11. [SUBMIT BUTTON]
  12.  
How would I go about adding a second or third phone number to the db?
The only way I can see to add another phone number would be to place an insert new button next to all of the fields that can have *many* of one thing such as customer location, phone number what have you but this design tenique does not strike me as clean.

I would ultimately like to have "one" submit button that will enter everything in one shot.

My second question has to do with SERIALIZABLE transactions. Is this hard to set up? Do I need to set up the entire db to use them? Again, just advice. Thanks Guys!

Frank
Jun 17 '07 #1
8 1837
shoonya
161 New Member
replying to your first query...
Expand|Select|Wrap|Line Numbers
  1. <script language=javascript>
  2. var counter=1 // present no of rows
  3. function add_row(){
  4. ---
  5. use pre defined addRow function here to add another row to the table.
  6. var inp=document.createElemet('INPUT')
  7. inp.id='input_text_field'+counter;
  8. //append the inp to newly added
  9. counter++
  10. --
  11. }
  12. </script>
  13. <table><tr><td><input type=text name=text_field_id0></td</tr></table> Telephone No <a href=javascript:add_row()>add another</a>
  14.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

assign the id's serially and put the whole thing in a form
On your php page
Expand|Select|Wrap|Line Numbers
  1. $i = 0;
  2. while ( isset ( $_POST["text_field_id".$i] ) ==1){
  3. --
  4. put your query here
  5. --
  6. $i++; 
  7. }
hope it's clean enough
you can also add remove option by deleting the rows in the table.
similarly implement this thing to all the fields that may have more than one values

for storing in db you can make a separate a table like telephone_no, contact_details else you can use array data type to store the information in a single table

shoonya
Jun 17 '07 #2
fjm
348 Contributor
Shoonya,


Thank you for you response and advice. I know that Yahoo mail has something similar when uploading a file (attachment). I'm not sure how to implement that into the code though. I am thinking about it and I'm not sure that it could work because I have a second table that is used as a FK in the phone table and indicates its type. Like this:

phone_Type_Tabl e
phone_Type

phone_table
phone_ID
phone_Type
area_Code
phone_Number
Some complete sample data would look like this:
Expand|Select|Wrap|Line Numbers
  1. phone_ID     phone_Type     area_Code     phone_Number
  2. 1                 Home                213                 555-1212
  3. 2                 Work                 312                        555-5455
  4.  
In order for me to use the javascript code you provided, wouldn't I have to also have some sort of a drop down box for the phone type as well? I just don't know how to impliment this.

Also, I have a question about my php design. Please bear in mind that this is my first real stab at trying to get something working with php. I have about 20 or so php forms written in pure html to look exactly how I want. I will go and insert the code into the html when I am ready.

My question is that I have seen many php scripts and I have never seen so many php scripts for each page. In other words, I usually see an index.php and class scripts. In my design, I will have 20 seperate php scripts and no classes. Is this a sucky design? Is there I way I can modulerize this some how without it becoming too difficult? I don't know OOP but I suspect that what I am referring to is OOP. Yes?

Thanks for the help.
Jun 19 '07 #3
shoonya
161 New Member
hey even I dont use/know OOP :D

now for your drop down which has to be generated from the phone_type relation
[PHP]<?php
$query="select phone_type from phone_no_type";
$result=pg_exec ($query);
if(!$result){
echo "<select size=1>";
for($i=0; $i<pg_num_rows( $result); $i++){
$data=pg_fetch_ array($result);
echo "<option>$d ata[phone_type]</option>";
}
echo "</select>";
}
?>[/PHP]

I guess this is what you want.
In case I am wrong do write back

shoonya
Jun 19 '07 #4
fjm
348 Contributor
hey even I dont use/know OOP :D

now for your drop down which has to be generated from the phone_type relation
[PHP]<?php
$query="select phone_type from phone_no_type";
$result=pg_exec ($query);
if(!$result){
echo "<select size=1>";
for($i=0; $i<pg_num_rows( $result); $i++){
$data=pg_fetch_ array($result);
echo "<option>$d ata[phone_type]</option>";
}
echo "</select>";
}
?>[/PHP]

I guess this is what you want.
In case I am wrong do write back

shoonya
The fact that you don't know OOP either makes me feel a whole lot better. :)

The code you provided will pull the data into a drop down box but can I incorporate that code into that nice little javascript code to dynamically appear when a new phone number is required?

I guess what I mean is that the js code will allow a new phone number but we also need the phone type to go with the new number for the parent table or the insert will fail.

Is there a way to bring up a new phone textbox field and phone type drop down box all in one click? Or maybe a better way of designing this all together?

Thanks Shoonya.
Jun 19 '07 #5
shoonya
161 New Member
yeah ofcourse you can do it
either use ajax to dynamically create the drop down each time user wants to enter a new telephone number
one alternate unorthodox method is make a javascript array like

content_array = new Array();
loop{
--
content_array[i]=<?php echo &tel_type; ?>
---}
now use this array to make a string like this

var arg='<select><o ption>'+content _array[0]+'</option><option> ......'
and now when any user will click to enter new phone no then along with showing him a text box show this string beside it or in a new cell

hope you will get it

shoonya
Jun 20 '07 #6
fjm
348 Contributor
yeah ofcourse you can do it
either use ajax to dynamically create the drop down each time user wants to enter a new telephone number
one alternate unorthodox method is make a javascript array like

content_array = new Array();
loop{
--
content_array[i]=<?php echo &tel_type; ?>
---}
now use this array to make a string like this

var arg='<select><o ption>'+content _array[0]+'</option><option> ......'
and now when any user will click to enter new phone no then along with showing him a text box show this string beside it or in a new cell

hope you will get it

shoonya
I'm sorry Shoonya.. its like showing a Japanese person Chinese writing. I don't understand javascript at all.

Is there or are there any ajax snippits out there that you could turn me on to that I can just kind of plug in? Maybe I am asking for something that is not possible. I don't know but it doesn't hurt to ask. :)

Thanks again. Frank
Jun 20 '07 #7
shoonya
161 New Member
no problem dude :)

I will suggest you to go through any javascript basic site (w3school is good and precise).
It will enhance your skill set and surely will be of great help
and yeah as fai as my knowledge is concerned ajax doesn't has a plug-in
it's an extension of javascript (very easy to use) used for fetching data from db without refreshing the whole page

shoonya
Jun 20 '07 #8
shoonya
161 New Member
go through some basic javascript functions/methods like

Expand|Select|Wrap|Line Numbers
  1. document.getElementById()
  2. ...innerHTML
  3. ...style.display
  4.  
shoonya
Jun 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4102
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
11
1926
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into this HTML file, all is OK but whenever the functions are separated (as it is now), when I run the page, I get the following error: Line 73, object expected.
4
1933
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <title>Calculator</title> <script language="Javascript"> <!-- Begin Hiding var total = 0
21
8217
by: Boris Ammerlaan | last post by:
This notice is posted about every week. I'll endeavor to use the same subject line so that those of you who have seen it can kill-file the subject; additionally, Supersedes: headers are used to ensure that only one copy resides on a given news server. This notice was last updated on March 9th, 2005, and is available (with a complete revision history) on the World Wide Web at http://www.stack.nl/~boris/HTML/ciwahfaq.html. Most of it was...
5
3597
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact that for server control component , code is running on the server side. But if I take as example a Label. I place on a webform an HTM label control and a WebForm label control, I could see that properties are different for
1
342
by: ankitvermamca | last post by:
I'm trying to dynamically add radio inputs to a form, but it's not working quite right. The code I have adds the radio buttons properly, but they are not selectable, and I can't seem to be able to retrieve the value. How do I fix it so they are selectable, and I can retrieve the value of the one the user selects? It only needs to work on IE5 or higher. Thanks in advance. Dex*
0
5577
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
3
3019
by: cuties | last post by:
Hi all.... i'm very new to this programming language. i'm required to fulfill this task in the company i'm doing my practical. i hope i can get guide for my problem... Here is the script i already wrote but i'm having problem to move forward. my problem is : 1. how do i assign each checkbox to have equal value with the value of the d_id?
4
20116
by: prosad | last post by:
hello, Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below: <script type="text/javascript"> function select_cell(obj) { document.getElementById('complaint').value = obj.innerText; document.getElementById('selected_form'); }
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.