Php表单不填充SQL数据库

时间:2014-05-15 06:37:36

标签: php mysql sql forms

我有一个工作正常的表单,但我需要在表单中添加12个字段。我将12个字段添加到数据库中,然后编辑了我的表单并添加了php中的所有字段和表单的html。表单通过电子邮件发送自己,但不填充数据库。没有错误消息,我已经多次查看过,无法找到遗漏的内容。相关部分如下。

  $sql="INSERT INTO `****`.`application_forms` (`firstName`, `middleName`, `lastName`, `streetAddress`, `city`, `state`, `zip`, `emailPreferred`, `emailAlternate`, `homePhone`, `cellPhone`, `workPhone`, `workPhoneExt`, `preferredContactMethod`, `faxNumber`, `employer`, `title`, `length`, `supervisor`, `supvtitle`, `supvcontact`, `workstreetAddress`, `workstreetAddress2`, `workcity`, `workstate`, `workzip`, `prevemployment`, `highSchool`, `highSchoolCity`, `highSchoolState`, `highSchoolDatesAttended`, `optionsGraduated`, `optionsAttendCollege`, `college`, `collegeCity`, `collegeState`, `collegeDatesAttended`, `collegeMajor`, `optionsCollegeGraduated`, `optionsGraduateSchool`, `gradSchool`, `gradSchoolCity`, `gradSchoolState`, `gradSchoolDatesAttended`, `gradSchoolMajor`, `optionsgradSchoolGraduated`, `specializedEducation`,  `leadershipExperience`, `awardsHonorsLeadershipActivities`, `outstandingLeaderNameQualities`, `strongestLeadershipAttr`, `communityServiceActivities`, `mostSignificantServiceExp`, `essayPartA`, `essayPartB`, `additionalRelevantInfo`, `howHearAboutLeadershipRockland`, `intendRequestPartialTuition`) VALUES ('$firstName', '$middleName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$emailPreferred', '$emailAlternate', '$homePhone', '$cellPhone', '$workPhone', '$workPhoneExt', '$preferredContactMethod', '$faxNumber', '$employer', '$title', '$length', '$supervisor', '$supvtitle', '$supvcontact', '$workstreetAddress', '$workstreetAddress2', '$workcity', '$workstate', '$workzip', '$prevemployment', '$highSchool', '$highSchoolCity', '$highSchoolState', '$highSchoolDatesAttended', '$optionsGraduated', '$optionsAttendCollege', '$optionsGraduateSchool', '$specializedEducation', '$leadershipExperience', '$awardsHonorsLeadershipActivities', '$outstandingLeaderNameQualities', '$strongestLeadershipAttr', '$communityServiceActivities', '$mostSignificantServiceExp', '$essayPartA', '$essayPartB', '$additionalRelevantInfo', '$howHearAboutLeadershipRockland', '$intendRequestPartialTuition')";

<?php 

              if( isset($_POST['applicationFormSubmit']) ) { 

                $checkifhuman = (isset($_POST['checkifhuman']) && (!empty($_POST['checkifhuman']))) ? $_POST['checkifhuman'] : "";
                $pageTitle;
                $pageMessage;

                if ($checkifhuman == "8") {

                  require 'PHPMailer/PHPMailerAutoload.php';

                  $firstName = (isset($_POST['firstName']) && (!empty($_POST['firstName']))) ? $_POST['firstName'] : "";
                  $middleName = (isset($_POST['middleName']) && (!empty($_POST['middleName']))) ? $_POST['middleName'] : "";
                  $lastName = (isset($_POST['lastName']) && (!empty($_POST['lastName']))) ? $_POST['lastName'] : "";
                  $streetAddress = (isset($_POST['streetAddress']) && (!empty($_POST['streetAddress']))) ? $_POST['streetAddress'] : "";
                  $city = (isset($_POST['city']) && (!empty($_POST['city']))) ? $_POST['city'] : "";
                  $state = (isset($_POST['state']) && (!empty($_POST['state']))) ? $_POST['state'] : "";;
                  $zip = (isset($_POST['zip']) && (!empty($_POST['zip']))) ? $_POST['zip'] : "";
                  $emailPreferred = (isset($_POST['emailPreferred']) && (!empty($_POST['emailPreferred']))) ? $_POST['emailPreferred'] : "";
                  $emailAlternate = (isset($_POST['emailAlternate']) && (!empty($_POST['emailAlternate']))) ? $_POST['emailAlternate'] : "";
                  $homePhone = (isset($_POST['homePhone']) && (!empty($_POST['homePhone']))) ? $_POST['homePhone'] : "";
                  $cellPhone = (isset($_POST['cellPhone']) && (!empty($_POST['cellPhone']))) ? $_POST['cellPhone'] : "";
                  $workPhone = (isset($_POST['workPhone']) && (!empty($_POST['workPhone']))) ? $_POST['workPhone'] : "";
                  $workPhoneExt = (isset($_POST['workPhoneExt']) && (!empty($_POST['workPhoneExt']))) ? $_POST['workPhoneExt'] : "";
                  $preferredContactMethod = (isset($_POST['optionsPreferredContactMethod']) && (!empty($_POST['optionsPreferredContactMethod']))) ? $_POST['optionsPreferredContactMethod'] : "";
                  $faxNumber = (isset($_POST['faxNumber']) && (!empty($_POST['faxNumber']))) ? $_POST['faxNumber'] : "";
                  $employer = (isset($_POST['employer']) && (!empty($_POST['employer']))) ? $_POST['employer'] : "";
                  $title = (isset($_POST['title']) && (!empty($_POST['title']))) ? $_POST['title'] : "";
                  $length = (isset($_POST['length']) && (!empty($_POST['length']))) ? $_POST['length'] : "";
                  $supervisor = (isset($_POST['supervisor']) && (!empty($_POST['supervisor']))) ? $_POST['supervisor'] : "";
                  $supvtitle = (isset($_POST['supvtitle']) && (!empty($_POST['supvtitle']))) ? $_POST['supvtitle'] : "";
                  $supvcontact = (isset($_POST['supvcontact']) && (!empty($_POST['supvcontact']))) ? $_POST['supvcontact'] : "";
                  $workstreetAddress = (isset($_POST['workstreetAddress']) && (!empty($_POST['workstreetAddress']))) ? $_POST['workstreetAddress'] : "";
                  $workstreetAddress2 = (isset($_POST['workstreetAddress2']) && (!empty($_POST['workstreetAddress2']))) ? $_POST['workstreetAddress2'] : "";
                  $workcity = (isset($_POST['workcity']) && (!empty($_POST['workcity']))) ? $_POST['workcity'] : "";
                  $workstate = (isset($_POST['workstate']) && (!empty($_POST['workstate']))) ? $_POST['workstate'] : "";
                  $workzip = (isset($_POST['workzip']) && (!empty($_POST['workzip']))) ? $_POST['workzip'] : "";
                  $prevemployment = (isset($_POST['prevemployment']) && (!empty($_POST['prevemployment']))) ? $_POST['prevemployment'] : "";                      
                  $highSchool = (isset($_POST['highSchool']) && (!empty($_POST['highSchool']))) ? $_POST['highSchool'] : "";
                  $highSchoolCity = (isset($_POST['highSchoolCity']) && (!empty($_POST['highSchoolCity']))) ? $_POST['highSchoolCity'] : "";
                  $highSchoolState = (isset($_POST['highSchoolState']) && (!empty($_POST['highSchoolState']))) ? $_POST['highSchoolState'] : "";
                  $highSchoolDatesAttended = (isset($_POST['highSchoolDatesAttended']) && (!empty($_POST['highSchoolDatesAttended']))) ? $_POST['highSchoolDatesAttended'] : "";
                  $optionsGraduated = (isset($_POST['optionsGraduated']) && (!empty($_POST['optionsGraduated']))) ? $_POST['optionsGraduated'] : "";
                  $optionsAttendCollege = (isset($_POST['optionsAttendCollege']) && (!empty($_POST['optionsAttendCollege']))) ? $_POST['optionsAttendCollege'] : "";
                  $college = (isset($_POST['college']) && (!empty($_POST['college']))) ? $_POST['college'] : "";
                  $collageCity = (isset($_POST['collegeCity']) && (!empty($_POST['collegeCity']))) ? $_POST['collegeCity'] : "";
                  $collegeState = (isset($_POST['collegeState']) && (!empty($_POST['collegeState']))) ? $_POST['collegeState'] : "";
                  $collageDatesAttended = (isset($_POST['collegeDatesAttended']) && (!empty($_POST['collegeDatesAttended']))) ? $_POST['collegeDatesAttended'] : "";
                  $collageMajor = (isset($_POST['collegeMajor']) && (!empty($_POST['collegeMajor']))) ? $_POST['collegeMajor'] : "";
                  $optionsCollegeGraduated = (isset($_POST['optionsCollegeGraduated']) && (!empty($_POST['optionsCollegeGraduated']))) ? $_POST['optionsCollegeGraduated'] : "";
                  $optionsGraduateSchool = (isset($_POST['optionsGraduateSchool']) && (!empty($_POST['optionsGraduateSchool']))) ? $_POST['optionsGraduateSchool'] : "";
                  $gradSchool = (isset($_POST['gradSchool']) && (!empty($_POST['gradSchool']))) ? $_POST['gradSchool'] : "";
                  $gradSchoolCity = (isset($_POST['gradSchoolCity']) && (!empty($_POST['gradSchoolCity']))) ? $_POST['gradSchoolCity'] : "";
                  $gradSchoolState = (isset($_POST['gradSchoolState']) && (!empty($_POST['gradSchoolState']))) ? $_POST['gradSchoolState'] : "";
                  $gradSchoolDatesAttended = (isset($_POST['gradSchoolDatesAttended']) && (!empty($_POST['gradSchoolDatesAttended']))) ? $_POST['gradSchoolDatesAttended'] : "";
                  $gradSchoolMajor = (isset($_POST['gradSchoolMajor']) && (!empty($_POST['gradSchoolMajor']))) ? $_POST['gradSchoolMajor'] : "";
                  $optionsgradSchoolGraduated = (isset($_POST['optionsgradSchoolGraduated']) && (!empty($_POST['optionsgradSchoolGraduated']))) ? $_POST['optionsgradSchoolGraduated'] : "";
                  $specializedEducation = (isset($_POST['specializedEducation']) && (!empty($_POST['specializedEducation']))) ? $_POST['specializedEducation'] : "";
                  $leadershipExperience = (isset($_POST['leadershipExperience']) && (!empty($_POST['leadershipExperience']))) ? $_POST['leadershipExperience'] : "";
                  $awardsHonorsLeadershipActivities = (isset($_POST['awardsHonorsLeadershipActivities']) && (!empty($_POST['awardsHonorsLeadershipActivities']))) ? $_POST['awardsHonorsLeadershipActivities'] : "";
                  $outstandingLeaderNameQualities = (isset($_POST['outstandingLeaderNameQualities']) && (!empty($_POST['outstandingLeaderNameQualities']))) ? $_POST['outstandingLeaderNameQualities'] : "";
                  $strongestLeadershipAttr = (isset($_POST['strongestLeadershipAttr']) && (!empty($_POST['strongestLeadershipAttr']))) ? $_POST['strongestLeadershipAttr'] : "";
                  $communityServiceActivities = (isset($_POST['communityServiceActivities']) && (!empty($_POST['communityServiceActivities']))) ? $_POST['communityServiceActivities'] : "";
                  $mostSignificantServiceExp = (isset($_POST['mostSignificantServiceExp']) && (!empty($_POST['mostSignificantServiceExp']))) ? $_POST['mostSignificantServiceExp'] : "";
                  $essayPartA = (isset($_POST['essayPartA']) && (!empty($_POST['essayPartA']))) ? $_POST['essayPartA'] : "";
                  $essayPartB = (isset($_POST['essayPartB']) && (!empty($_POST['essayPartB']))) ? $_POST['essayPartB'] : "";
                  $additionalRelevantInfo = (isset($_POST['additionalRelevantInfo']) && (!empty($_POST['additionalRelevantInfo']))) ? $_POST['additionalRelevantInfo'] : "";
                  $howHearAboutLeadershipRockland = (isset($_POST['howHearAboutLeadershipRockland']) && (!empty($_POST['howHearAboutLeadershipRockland']))) ? $_POST['howHearAboutLeadershipRockland'] : "";
                  $intendRequestPartialTuition = (isset($_POST['intendRequestPartialTuition']) && (!empty($_POST['intendRequestPartialTuition']))) ? $_POST['intendRequestPartialTuition'] : "";

2 个答案:

答案 0 :(得分:1)

您没有执行sql。使用mysql_query()执行它,例如:

 $sql="INSERT INTO `****`.`application_forms` (`firstName`, `middleName`, `lastName`, `streetAddress`, `city`, `state`, `zip`, `emailPreferred`, `emailAlternate`, `homePhone`, `cellPhone`, `workPhone`, `workPhoneExt`, `preferredContactMethod`, `faxNumber`, `employer`, `title`, `length`, `supervisor`, `supvtitle`, `supvcontact`, `workstreetAddress`, `workstreetAddress2`, `workcity`, `workstate`, `workzip`, `prevemployment`, `highSchool`, `highSchoolCity`, `highSchoolState`, `highSchoolDatesAttended`, `optionsGraduated`, `optionsAttendCollege`, `college`, `collegeCity`, `collegeState`, `collegeDatesAttended`, `collegeMajor`, `optionsCollegeGraduated`, `optionsGraduateSchool`, `gradSchool`, `gradSchoolCity`, `gradSchoolState`, `gradSchoolDatesAttended`, `gradSchoolMajor`, `optionsgradSchoolGraduated`, `specializedEducation`,  `leadershipExperience`, `awardsHonorsLeadershipActivities`, `outstandingLeaderNameQualities`, `strongestLeadershipAttr`, `communityServiceActivities`, `mostSignificantServiceExp`, `essayPartA`, `essayPartB`, `additionalRelevantInfo`, `howHearAboutLeadershipRockland`, `intendRequestPartialTuition`) VALUES ('$firstName', '$middleName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$emailPreferred', '$emailAlternate', '$homePhone', '$cellPhone', '$workPhone', '$workPhoneExt', '$preferredContactMethod', '$faxNumber', '$employer', '$title', '$length', '$supervisor', '$supvtitle', '$supvcontact', '$workstreetAddress', '$workstreetAddress2', '$workcity', '$workstate', '$workzip', '$prevemployment', '$highSchool', '$highSchoolCity', '$highSchoolState', '$highSchoolDatesAttended', '$optionsGraduated', '$optionsAttendCollege', '$optionsGraduateSchool', '$specializedEducation', '$leadershipExperience', '$awardsHonorsLeadershipActivities', '$outstandingLeaderNameQualities', '$strongestLeadershipAttr', '$communityServiceActivities', '$mostSignificantServiceExp', '$essayPartA', '$essayPartB', '$additionalRelevantInfo', '$howHearAboutLeadershipRockland', '$intendRequestPartialTuition')";
 mysql_query($sql);

答案 1 :(得分:1)

不推荐使用mysql_query,mysql_connect和任何带有mysql_前缀的数据库函数。改为使用mysqli_connect()和mysqli_query()。

所以,

$sql="INSERT INTO `****`.`application_forms` (`firstName`, `middleName`, `lastName`, `streetAddress`, `city`, `state`, `zip`, `emailPreferred`, `emailAlternate`, `homePhone`, `cellPhone`, `workPhone`, `workPhoneExt`, `preferredContactMethod`, `faxNumber`, `employer`, `title`, `length`, `supervisor`, `supvtitle`, `supvcontact`, `workstreetAddress`, `workstreetAddress2`, `workcity`, `workstate`, `workzip`, `prevemployment`, `highSchool`, `highSchoolCity`, `highSchoolState`, `highSchoolDatesAttended`, `optionsGraduated`, `optionsAttendCollege`, `college`, `collegeCity`, `collegeState`, `collegeDatesAttended`, `collegeMajor`, `optionsCollegeGraduated`, `optionsGraduateSchool`, `gradSchool`, `gradSchoolCity`, `gradSchoolState`, `gradSchoolDatesAttended`, `gradSchoolMajor`, `optionsgradSchoolGraduated`, `specializedEducation`,  `leadershipExperience`, `awardsHonorsLeadershipActivities`, `outstandingLeaderNameQualities`, `strongestLeadershipAttr`, `communityServiceActivities`, `mostSignificantServiceExp`, `essayPartA`, `essayPartB`, `additionalRelevantInfo`, `howHearAboutLeadershipRockland`, `intendRequestPartialTuition`) VALUES ('$firstName', '$middleName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$emailPreferred', '$emailAlternate', '$homePhone', '$cellPhone', '$workPhone', '$workPhoneExt', '$preferredContactMethod', '$faxNumber', '$employer', '$title', '$length', '$supervisor', '$supvtitle', '$supvcontact', '$workstreetAddress', '$workstreetAddress2', '$workcity', '$workstate', '$workzip', '$prevemployment', '$highSchool', '$highSchoolCity', '$highSchoolState', '$highSchoolDatesAttended', '$optionsGraduated', '$optionsAttendCollege', '$optionsGraduateSchool', '$specializedEducation', '$leadershipExperience', '$awardsHonorsLeadershipActivities', '$outstandingLeaderNameQualities', '$strongestLeadershipAttr', '$communityServiceActivities', '$mostSignificantServiceExp', '$essayPartA', '$essayPartB', '$additionalRelevantInfo', '$howHearAboutLeadershipRockland', '$intendRequestPartialTuition')"; 

mysqli_query($sql);

在if(isset($ _ POST ['applicationFormSubmit'])){}块的底部执行此操作