Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form question

Status
Not open for further replies.

sipps

Technical User
Feb 9, 2003
133
GB
Hi,

I have a little query about form stuff.
I want to be able to let people choose a location from a dropdown box. When they choose this location, I want some textfield boxes below to show the data that goes with that location.
So customers come and choose "London" for example;
and the boxes get filled:

Location Name "London"
Location Address "City Center"
Location Email "city@london.com"
etc.....

When these boxes are filled, I want them to be able to edit the data, so change the email to "mayor@london.com" and then update this in the database(MySQL).

Will I need a submit button for the drop down box, and another one for the update? Also, can I do all this on the same page?

Thanks for your help guys!
 
I recommend that you provide a submit button for the drop-down box.

As far as doing it on the same page, sure. When the dropdown is submitted, have the script to which that form submits output the dropdown again (with the correct entry pre-selected) along with the new fields.

I also recommend that you have the script provide a hidden field which matches the dropdown entry originally selected. That way, your script can correctly detect that your user has changed the value in that dropdown and react accordingly. Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanks sleipnir214,

I am doing this in Dreamweaver as I cant really code it by hand. I can add scripts to the HTML though. How would I script this in, and what code should I use? I don't know how to call the same page and take the selected location across and do all that stuff.
Also, I have a Location_ID which I am not showing to the user as it is an autonumber and shouldn't be updated, so when I use Update, how can I make sure if updates the right row?

Thanks!!
 
Hide the location id in a hidden HTML form field.

I'm unfamiliar with Dreamweaver or what it's limitations are. I generally use a syntax-highlighting text editor to code PHP.

What I would do is create a single script that does the whole thing.

The script will expect input via POST and will submit back to itself.

1. If it gets no input, it produces the first dropdown, the hidden location id, and a submit button.

2. If it gets input from the dropdown, it reproduces the dropdown (with the previously-chosen item pre-selected), the hidden location id, a hidden field which duplicates the dropdown input from the first form, the extra fields and a submit.

3. If it gets all the fields, it checks to make sure the user has not changed the selection in the dropdown. If it does, it will go back to state 2. If it does not detect a change, it will perform the update.
Want the best answers? Ask the best questions: TANSTAAFL!
 
I have TextPad, and use that for HTML editing as Dreamweavver isn't great for everything!
I can copy my HTML code into this and add the PHP scripts no problem. The issues I have is that I do not know how to write the PHP scripts! I have many questions about PHP for my site, but if I could get some help on examples of showing data on screen, updating it, inserting new data, and deleting it, then I think I could get the rest done. I have been able to insert new locations, but one problem is that when I press the insert button and there are no values in there, it still inserts nulls into the db, well bad practice!

But back to the original problem, I have no idea where to start to script the functions you have suggested.
I use the <form name=&quot;editlocation&quot; action=&quot;modlocdetails.php&quot; method=&quot;post&quot;> and when I hit submit it returns to the same page, but as for taking what was selected in the drop down and putting that in the hidden field and filling the textfields with the database info, I don't know how to do that!

The stage I am at is that users can see the different locations in the drop down, I just want them to select one and edit the details that come up in the form and update the db.

Thanks again, sorry I'm no good at this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top