Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:57:35+00:00 2026-05-31T15:57:35+00:00

I am working on a basic add/edit/delete form using PEAR DB. My add and

  • 0

I am working on a basic add/edit/delete form using PEAR DB. My add and delete functions are working correctly, but my edit function is creating a duplicate record instead of editing the active record.

I have searched the forums, the MySQL manual, and php.net, but there isn’t much documentation out there. The site I am working on is old, and I understand that very few people are working with Pear DB, as frameworks like CodeIgniter are now the way to go. I would switch this site over if I could, believe me. That said, any help sorting this out would be greatly appreciated!

Here’s my code:

<?php 

require 'controller.php';
global $dbc;
$member_id = $_GET['memberid'];
$aid = $_GET['aid'];

/* Handle Accounting Actions -- Add, Edit, Delete */

$action = isset( $_GET['action'] ) ? $_GET['action'] : "";

switch ($action) {

  case 'add':
    add_aid();
    break;

  case 'edit':
    edit_aid();
    break;

  case 'delete':
    delete_aid();
    break;

  default:
    add_aid();
    break;
}


function add_aid()
{
    global $dbc;
    $member_id = $_GET['memberid'];
    $aid = $_GET['aid'];

?>


    <form name="add accounting record" action="?module=members&amp;mode=edit" method="post">        

    <input type="hidden" id="member_id" name="member_id" value="<?=$member_id?>" />

        <table style="border: 1px solid #000;" align="center">
            <tr style="background-color: #525f3b;">
                <th style="background-color: #525f3b;color: #b5d67a;text-transform: uppercase; align:center; font-family: Arial, Helvetica, sans-serif;" colspan="5" >Accounting</th>
            </tr>

            <tr style="background-color:#b5d67a; color:#525f3b;text-transform: uppercase; font-family: Arial, Helvetica, sans-serif; font-size:12px;">
                <td>Actions</td><td>Year</td><td>Dues Pd. (Date)</td><td>Amount Pd.</td><td>Attended<br>Conference<br>(Date)</td>
            </tr>

            <tr style="background-color:#b5d67a; border-right: 1px solid #000; color:#525f3b;text-transform: uppercase; font-family: Arial, Helvetica, sans-serif;">
                <td align="center">

                    <a href="?module=memberss&amp;mode=edit&amp;aid='<?php print $data['aid'];?>" title="Edit"><img src="images/icons/icon-edit.png" class="inline_icon" alt="Edit" /></a> <a onclick="return window.confirm(\'Are you sure you want to delete this record?\');" href="?module=members&amp;action=delete&amp;aid=<?php print $data[0];?>" title="Delete"><img src="images/icons/icon-delete.png" class="inline_icon" alt="Delete" /></a>

                </td>

                <td>
                    <input type="text" id="year" name="year" value="<?=$_POST['year']?>" size="10" maxlength="4" />
                </td>

                <td>
                    <input type="text" id="dues_paid_date" value="<?=$_POST['dues_paid_date']?>" name="dues_paid_date" size="20" maxlength="10"  />
                </td>

                <td>
                    <input type="text" id="amount_paid" value="<?=$_POST['amount_paid']?>" name="amount_paid" size="20" maxlength="16" />
                </td>

                <td>
                    <input type="text" id="attended_conf" value="<?=$_POST['attended_conf']?>" name="attended_conf" size="20" maxlength="10" />
                </td>

            </tr>

        </table>
        <div style="float:right;">
            <input class="form_button" style="float:right;" type="submit" value="CLOSE WINDOW" onclick="window.opener.location.href = window.opener.location.href; window.close();">
        </div>
        <div style="float:right;">
            <input class="form_button" type="submit" value="SAVE DATA" onclick="this.form.submit();" />
        </div
    </form>

</div>
<?php

    if (isset($_POST['year']) &&
        isset($_POST['dues_paid_date']) &&
        isset($_POST['amount_paid']) &&
        isset($_POST['attended_conf']))

        {
            $member_id = (int)$_POST['member_id'];
            $year = ($_POST['year']);
            $dues = ($_POST['dues_paid_date']);
            $amount = ($_POST['amount_paid']);
            $conference = ($_POST['attended_conf']);

        $res =& $dbc->query("INSERT INTO accounting (member_id,year, dues_paid_date, amount_paid, attended_conf) VALUES ('".$member_id."','".$year."','".$dues."','".$amount."','".$conference."')",null,null);
        }
}

function edit_aid()
{
    global $dbc;
    $member_id = $_GET['memberid'];
    $aid = $_GET['aid'];

    $dbQuery = "SELECT *
                FROM accounting
                WHERE member_id='".$member_id."'
                AND aid='".$aid."'
                LIMIT 0,1";
    $dbResult = $dbc->query( $dbQuery,__FILE__,__LINE__ );
    $adata = $dbResult->fetchRow( DB_FETCHMODE_ASSOC );

    $year = ($adata['year']);
    $dues = ($adata['dues_paid_date']);
    $amount = ($adata['amount_paid']);
    $conference = ($data['attended_conf']);

    ?>

    <form name="edit contact" action="?module=members&amp;mode=edit" method="post">     

        <input type="hidden" id="member_id" name="member_id" value="<?=$member_id?>" />

        <input type="hidden" id="aid" name="aid" value="<?=$aid?>" />
        <?php //echo $member_id; ?>

            <label value="<?=$adata['Year']?>">Year</label>
                <input type="text" id="year" name="year" value="<?=$adata['year'];?>" size="20" maxlength="20" />

            <label value="<?=$adata['dues_paid_date']?>">Dues Paid Date</label>
                <input type="text" id="dues_paid_date" name="dues_paid_date" value="<?=$adata['dues_paid_date']?>" size="20" maxlength="20"  />
            <label value="<?=$adata['amount_paid']?>">Amount Paid</label>
                <input type="text" id="amount_paid" name="amount_paid" value="<?=$adata['amount_paid']?>" size="45" maxlength="60" />
            <label value="<?=$adata['attended_conf']?>">Attended Conference</label>
                <input type="text" id="attended_conf" name="attended_conf" value="<?=$adata['attended_conf']?>" size="30" maxlength="30" />

            <div style="float:right;">
                <input class="form_button" type="submit" value="SAVE DATA" onclick="this.form.submit();" />
            </div
        </form>

    <?php
    $dbQuery = "UPDATE accounting
        SET member_id='".$member_id."', year='".$year."', dues_paid_date='".$dues."', amount_paid='".$amount."', attended_conf='".$conference."' 
            WHERE member_id='".$member_id."'
            AND aid='".$aid."'";
    $dbc->query( $dbQuery,__FILE__,__LINE__ );

    $_SESSION['msg'] = 'The contact was successfully updated.';
    }


function delete_aid()
{
    global $dbc;
    $member_id = $_GET['memberid'];
    $aid = $_GET['aid'];

    $dbQuery = "SELECT *
                FROM accounting
                WHERE member_id='".$member_id."'
                AND aid='".$aid."'
                LIMIT 0,1";
    $dbResult = $dbc->query( $dbQuery,__FILE__,__LINE__ );
    $adata = $dbResult->fetchRow( DB_FETCHMODE_ASSOC );

    ?>

    /* Echo the data, confirm we want to delete */

<input class="form_button" style="float:right;" type="submit" value="REMOVE RECORD" onclick="window.opener.location.href = window.opener.location.href; window.close();">
            </div>
    <?php
    $dbQuery = "DELETE FROM accounting
                WHERE member_id='".$member_id."'
                AND aid='".$aid."'";
    $dbc->query( $dbQuery,__FILE__,__LINE__ );

    $_SESSION['msg'] = 'The contact was successfully deleted.';
    }

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:57:36+00:00Added an answer on May 31, 2026 at 3:57 pm

    You’re are using ‘mode’ in your form action as the key but you are looking for $_GET['action'] instead of $_GET['mode']. This is causing the default from your switch to run since there is no $_GET['action']

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apple's documentation on UITableView discusses how to add/edit/delete rows, but it doesn't discuss adding/editing/deleting
I'm working on a database backup engine using JPA. Everything is working fine but
I have a basic working knowledge of Castle Windsor, but I cannot figure out
I have a service, as follows: The most basic (working) CherryPy 3.1 Windows service
I am working in Visual Basic 6 and need to sort by multiple columns
I am working on a basic Struts based application that is experience major spikes
I'm working on a basic Issue Management System in order to learn ASP.NET MVC.
I'm working on a basic google applications based system. Like I earlier defined I'm
I'm working on a basic garden logging application which consists of gardens, plants and
I'm working on a basic DBMS as a pet project and planning to prototype

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.