Wrox Programmer Forums
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 16th, 2005, 07:18 AM
Registered User
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit Form Query

Hi All,

I am still relatively new to PHP and MySQL but have been able to get quite a way with info available on the web.

OK ... I want to edit a record in my database using PHP. My main table (the one I want to edit) contains references to other tables. My original entry form dynamically queries the other tables and stores the id in the main table.

So the question now is how do I load an existing record in the edit form, default what was previously entered and show dynamically the other entries in the other table? Hope this makes sense?

e.g. for the main table I query the location table and retrieve the id, description and value fields (used later for calculations). The user selects the appropriate description and the database stores the id.

Thanks in advance for any help!

Old November 18th, 2005, 04:27 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul

You're asking about relational db and normalization. In short, your tables are connected via IDs. A table typically has its own ID and other IDs that reference other tables.

In SQL, WHERE clause helps to join tables while querying ..
like WHERE tablename1.id = tablename2.id

If you're still confused, show us few lines of code. We also need know your db structure, to help you, specifically. By the way, MSQL AB (mysql.net) already provides free comprehensive documentation for all the explaination. We all are ourselves reading that.

Support Indian students' finances http://scholarship.mediasworks.com/
Old November 18th, 2005, 08:59 AM
Registered User
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks Anshul,

OK I have a table called "ops" and one of many tables called "agerisk". The agerisk table has an id field, description and value fields. I use the id field on the ops table to reference the appropriate row (id) in the "agerisk" table. The user is presented the description field in the combo box on the form. I have included some code from the original form below. I am struggling to understand how I can construct the same lookup to default what was entered by the user when they wish to edit/update the data.

          <select name=\"agerisk2\">
        <option value=\"\"></option>";

        for($i=0; $i<$ageriskNumber; $i++) {
            $ageriskAgeid = mysql_result($ageriskResult,$i,"agerisk.ageid");
            $ageriskDescription = mysql_result($ageriskResult,$i,"agerisk.Descriptio n");
            print " <option value=\"$ageriskAgeid\">$ageriskDescription</option>";


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Table through a Form Coby Access VBA 3 August 17th, 2007 07:10 AM
Form view control, Authorized edit only nuttylife2 ASP.NET 2.0 Professional 0 July 10th, 2006 07:57 PM
2 tables, 1 query, 1 form, cannot edit :( tanjuakio Access 2 June 24th, 2005 06:24 AM
Edit form mrideout BOOK: Beginning ASP.NET 1.0 0 August 25th, 2004 04:32 PM
How form can edit mateenmohd VB Databases Basics 2 June 22nd, 2003 02:43 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.