Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

PHP/MySQL: 'Add New' text field from menu in form

New Here ,
May 18, 2009 May 18, 2009

Copy link to clipboard

Copied

I am creating an events posting website. I'm having a hard time finding the right words to describe this, but: I'd like the user to select a venue from the drop menu, but then if it isn't there, to select 'add new' from the dynamic menu, and have a new text field activate where they can enter in the new venue name. My database is currently set up so the event table links to the venue table through a venueID. Is there a way to insert the name from the new text field into the venue table, and have the rest of the form still submit to the event table? Sorry this is so wordy, but I'd appreciate any help. Thank you.

TOPICS
Server side applications

Views

465
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2009 May 19, 2009

Copy link to clipboard

Copied

LATEST

You cannot add a new value to a related table at the same time as inserting a record. So, to do this, you would need to use both JavaScript to add the new text field, and PHP conditional logic to handle the update to both tables. It's certainly doable, but not with the Dreamweaver server behaviors. You would need to do a lot of hand-coding yourself.

The way that I approached a similar problem in my "Essential Guide to Dreamweaver CS4" was to permit NULL values in the column that holds the foreign key, and insert nothing into that field if the value hadn't already been registered in the related table. I created a static value in the dynamic menu for "Not registered".

After inserting the new record with "not registered", the user then needs to enter the new value in the related table.

Once that has been done, display a page that lists all records. In the SQL, I use a LEFT JOIN to ensure that "not registered" items come up as well. You can then edit the item to add the value from the dynamic menu.

It's not the most elegant way to do it, but it works if you don't have the skill or time to hand-code all the logic yourself.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines