473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to make a "sophisticated" insert record form ?

hello
I have a DB with many inter-related tables (MySQL)
My main table called "content" has almost only foreign keys (integers)
some have a 3 level relation (ex: content->city->region->country)

I would like admins to be able to insert new records including all the
"content" fields (in 1 page form)

But how can I make an insert form that would display the related
tables as list menus instead of a textfield with a number? (ex: select
country from a drop down menu instead of typing the foerign key
number)

Main content Table:
IDRef = primary key
IDLocation = foreign key --related to tables city->region->country
IDDescription = foreign key --related to table Description (=several
big and small text fields)
IDImages = foreign key --related to image (=image and thumbs path, alt
text, etc..)

Do you know any tutorial, help or solution ?

Thank you very much
Jul 17 '05 #1
2 4672
er**********@yahoo.fr (EricRobineau) wrote in message
news:<c4**************************@posting.google. com>...

I have a DB with many inter-related tables (MySQL)
My main table called "content" has almost only foreign keys (integers)
some have a 3 level relation (ex: content->city->region->country)

I would like admins to be able to insert new records including all the
"content" fields (in 1 page form)

But how can I make an insert form that would display the related
tables as list menus instead of a textfield with a number? (ex: select
country from a drop down menu instead of typing the foerign key
number)


Since I don't know how your tables are set up, let me offer a
hypothetical example...

You have three tables:

content:
IDRef
IDLocation
IDDescription

country:
ID
name

items:
ID
description

To add a new item, whose description will then be associated
with a country, you need something like this (assuming the connection
to the database has already been established):

$select = 'SELECT * FROM country ORDER BY name';
$selected = mysql_query ($select)
or die ('Can't execute the SELECT query...');
echo '<form action="insert.php" method="POST">',
'Enter item's description: <br>',
'<textarea name="description"></textarea>',
'<select name="countryID">';
while ($record = mysql_fetch_array ($selected)) {
echo '<option value="', $record['ID'],
'">', $record['name'];
}
echo '</select><br>',
'<input type="submit" value="Insert">',
'</form>';

This form will generate a POST submission with two fields:
'countryID' and 'description'. Your next script can handle
this submission as a transaction (for brevity, I am not
writing any error checks or ROLLBACKs):

mysql_query ('BEGIN');
mysql_query ("INSERT INTO items SET description = '" .
$_POST['description'] . "'")
or die ();
$itemsID = mysql_insert_id ()
or die ();
mysql_query ("INSERT INTO content SET IDLocation = '" .
$_POST['ID'] . "', IDDescription = '$itemsID'")
or die ();
mysql_query ('COMMIT');

Arranging two INSERT queries into transaction ensures that data
is entered either completely or not at all.

Cheers,
NC
Jul 17 '05 #2
I'm still a newbie so I'm not sure I got it all but I have a good example to
start with
Thanks for your help
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
0
by: Frederick Noronha \(FN\) | last post by:
---------- Forwarded message ---------- Solutions to Everyday User Interface and Programming Problems O'Reilly Releases "Access Cookbook, Second Edition" Sebastopol, CA--Neither reference book...
34
by: John Harrison | last post by:
An odd confession; an odd request; but here's the tale.... My company has a few PC systems which we have used for about 7 years and not updated - we've "made do", and besides, "if it ain't...
8
by: Tim Geiges | last post by:
Since I am being challenged with learning c# I figured I could pass some of the pain on to you guys :-) I have another question(this one is important for me to fix before I can get my app to Beta)...
2
by: Ivan Weiss | last post by:
Hi. This is a question I have posted before and have never figured out a working result. I have been recommended to read some books which I did which still have not answered my question. I am...
11
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in...
4
by: Burt | last post by:
I'm working on a Windows app that pulls data from SQL Server, displays it on various forms and grids, and allows the user to update, insert, delete data. Some but not much business logic, just...
3
Frinavale
by: Frinavale | last post by:
I have been researching the best approach to migrating a VB6 application into a VB.NET application. There is a lot of information out there but most of it recommends that you "train in the migration...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.