MySQL query not recognizing variables passed to parameter array

Posted on 2011-04-24
Last Modified: 2013-12-12
I am processing output from a form, but I keep getting "Undefined variable" for the variables I have assigned to my query parameter array.

Error message:
Error Number: 8
TEXT: Undefined variable: ParentGuardianLastNameJP
LOCATION: /Applications/MAMP/htdocs/eng_adv_v2/business/contact.php, line 82, at April 25, 2011, 6:53 am
Showing backtrace:
Contact.UpdateParent("459", "¿¿¿¿", "¿¿¿", "Karl", "Pisor", "03-5696-2577", "080-3276-4570", "", "134-0085", "1", "Edogawa-ku", "Minami Kasai 5-5-18-401", "") # line   93, file: /Applications/MAMP/htdocs/eng_adv_v2/template_process.php

...the same message is for all of the passed variables...

Here's the PHP in template_process.php:

        // initialize error message
      $error_msg = '';
      // update parent record
      if (isset($_POST['RegSubmit'])) {
            // get the user-entered data
            $ParentGuardianPK = $_SESSION['ParentId'];
            $ParentGuardianLastNameJP = trim($_POST['ParentGuardianLastNameJP']);
            $ParentGuardianFirstNameJP = trim($_POST['ParentGuardianFirstNameJP']);
            $ParentGuardianFirstNameEN = trim($_POST['ParentGuardianFirstNameEN']);
            $ParentGuardianLastNameEN = trim($_POST['ParentGuardianLastNameEN']);
            $ParentGuardianPhone = trim($_POST['ParentGuardianPhone']);
            $ParentGuardianEmerPhone = trim($_POST['ParentGuardianEmerPhone']);
            $ParentGuardianEmail = trim($_POST['ParentGuardianEmail']);
            $ParentGuardianPostalCode = trim($_POST['ParentGuardianPostalCode']);
            $ParentGuardianPrefectureFK = trim($_POST['ParentGuardianPrefectureFK']);
            $ParentGuardianCityTown = trim($_POST['ParentGuardianCityTown']);
            $ParentGuardianAddress1 = trim($_POST['ParentGuardianAddress1']);
            $ParentGuardianAddress2 = trim($_POST['ParentGuardianAddress2']);
            // server-side validation on name entry
            if (!empty($ParentGuardianFirstNameEN) && !empty($ParentGuardianLastNameEN)) {
                  // process update
                  $updateParentResult = Contact::UpdateParent(
                  // update is okay
                  if ($updateParentResult) {
                        $error_msg = 'Update executed correctly';
                  } else {
                        // query returns 0 results. Throw error.
                        $error_msg = 'Error with update';
            } else {
                  // this generic error is testing the client-side validation again
                  $error_msg = $AdminLoginError_FormError;
            } // end server-side validation
      } // end RegSubmit

Here's my query setup in contact.php:

public static function UpdateParent()
                  // Write SQL statement
                  $sql = 'CALL contact_update_parent(
                  // Build the parameters array
                  $params = array(
                                      ':pk_contact' => $ParentGuardianPK,
                                      ':lastname_jp' => $ParentGuardianLastNameJP,
                                      ':firstname_jp' => $ParentGuardianFirstNameJP,
                                      ':firstname_en' => $ParentGuardianFirstNameEN,
                                      ':lastname_en' => $ParentGuardianLastNameEN,
                                      ':phone' => $ParentGuardianPhone,
                                      ':emergency_phone' => $ParentGuardianEmerPhone,
                                      ':email' => $ParentGuardianEmail,
                                      ':postalcode' => $ParentGuardianPostalCode,
                                      ':fk_prefecture' => $ParentGuardianPrefectureFK,
                                      ':city_town' => $ParentGuardianCityTown,
                                      ':address1' => $ParentGuardianAddress1,
                                      ':address2' => $ParentGuardianAddress2);              
                  // Execute the query and return the results
                  return DatabaseHandler::Execute($sql, $params);

Here's the SQL:

PROCEDURE contact_update_parent
  UPDATE contact
  t_lastname_jp = inLastNameJP,
  t_firstname_jp = inFirstNameJP,
  t_firstname_en = inFirstNameEN,
  t_lastname_en = inLastNameEN,
  t_phone = inPhone,
  t_phone_emergency = inPhoneEmergency,
  t_email = inEmail,
  t_postalcode = inPostalCode,
  fk_prefecture = inPrefectureFK,
  t_city = inCity,
  t_address1 = inAddress1,
  t_address2 = inAddress2
  WHERE  pk_contact = inParentPK;
  IN inParentPK int(10),
  IN inLastNameJP varchar(255),
  IN inFirstNameJP varchar(255),
  IN inFirstNameEN varchar(255),
  IN inLastNameEN varchar(255),
  IN inEmail varchar(100),
  IN inPhone varchar(50),
  IN inPhoneEmergency varchar(50),
  IN inPostalCode varchar(30),
  IN inPrefectureFK int(10),
  IN inCity varchar(100),
  IN inAddress1 varchar(100),
  IN inAddress2 varchar(100)

Question by:kpisor
    LVL 24

    Accepted Solution

    I'm not a PHP programmer but it looks like the problem is not in MySQL but the PHP code.  Shouldn't there be parameters inside the parentheses in the line below in contact.php?  That's usually the case for function definitions in the languages I use.

    public static function UpdateParent()

    Author Closing Comment

    Perfect. I just didn't declare the parameters in the function. I fixed that and it worked first time. Thanks!

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    PHP Radio Array 4 28
    undefined index setting cookie 11 29
    Bing Maps 1 23
    MySQL Server 5.5.36 Tuning 9 30
    As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now