[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySQL query not recognizing variables passed to parameter array

Posted on 2011-04-24
2
Medium Priority
?
346 Views
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", "karl@pisor.org", "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(
                                                            $ParentGuardianPK,
                                                            $ParentGuardianLastNameJP,
                                                            $ParentGuardianFirstNameJP,
                                                            $ParentGuardianFirstNameEN,
                                                            $ParentGuardianLastNameEN,
                                                            $ParentGuardianPhone,
                                                            $ParentGuardianEmerPhone,
                                                            $ParentGuardianEmail,
                                                            $ParentGuardianPostalCode,
                                                            $ParentGuardianPrefectureFK,
                                                            $ParentGuardianCityTown,
                                                            $ParentGuardianAddress1,
                                                            $ParentGuardianAddress2
                                                            );
                  
                        
                  // 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(
                                      :pk_contact,
                                      :lastname_jp,
                                      :firstname_jp,
                                      :firstname_en,
                                      :lastname_en,
                                      :phone,
                                      :emergency_phone,
                                      :email,
                                      :postalcode,
                                      :fk_prefecture,
                                      :city_town,
                                      :address1,
                                      :address2)';      
                                     
                  // 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
BEGIN
  UPDATE contact
  SET    
  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;
END
  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)

0
Comment
Question by:kpisor
2 Comments
 
LVL 24

Accepted Solution

by:
johanntagle earned 2000 total points
ID: 35457522
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()
0
 

Author Closing Comment

by:kpisor
ID: 35457573
Perfect. I just didn't declare the parameters in the function. I fixed that and it worked first time. Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

829 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