MySQL表只能从EXT js + PHP条目第一次提交

时间:2013-04-25 12:01:04

标签: php mysql extjs

我的MySQL出了问题。

我已经完成了所有设置并且一切都很顺利,但是当我提交表单时,它只有在表格完全为空时才会起作用。如果表中已存储信息,则不会提交其他条目。

这是mysql表

CREATE TABLE student
(StudentID int NOT NULL,
StudentFirst varchar(30),
StudentLast varchar(30), 
StudentEmail varchar(254),
StudentPhone varchar(12),
StudentDOB date,
DateStarted date, 
LessonID int,
StudentAddress varchar(50), 
StudentCity varchar(30), 
StudentState char(2), 
StudentZip varchar(10), 
MusicInterest text);
alter table student add constraint StudentPK primary key AUTO_INCREMENT (StudentID); 
alter table student add constraint LessonFK foreign key (LessonID) references lesson(LessonID);

这是我的PHP

if(isset($_REQUEST['action'])){
switch($_REQUEST['action']){
        case 'submit_student':
            $first = $_REQUEST['StudentFirst'];
            $last = $_REQUEST['StudentLast'];
            $email = $_REQUEST['StudentEmail'];
            $phone = $_REQUEST['StudentPhone'];
            $dob = $_REQUEST['StudentDOB'];
            $datestarted = $_REQUEST['DateStarted'];
            $lessonid = $_REQUEST['LessonID'];
            $address = $_REQUEST['StudentAddress'];
            $city = $_REQUEST['StudentCity'];
            $state = $_REQUEST['StudentState'];
            $zip = $_REQUEST['StudentZip'];
            $musicinterest = $_REQUEST['MusicInterest'];


            $stmt = $dbh->prepare("insert into student (StudentFirst, StudentLast, StudentEmail,  StudentPhone, StudentDOB, DateStarted, LessonID, StudentAddress, StudentCity, StudentState, StudentZip,MusicInterest) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
            $stmt -> bindParam(1,$first);
            $stmt -> bindParam(2,$last);
            $stmt -> bindParam(3,$email);
            $stmt -> bindParam(4,$phone);
            $stmt -> bindParam(5,$dob);
            $stmt -> bindParam(6,$datestarted);
            $stmt -> bindParam(7,$lessonid);
            $stmt -> bindParam(8,$address);
            $stmt -> bindParam(9,$city);
            $stmt -> bindParam(10,$state);
            $stmt -> bindParam(11,$zip);
            $stmt -> bindParam(12,$musicinterest);
            $stmt -> execute();
        break;

和我的EXTJs

function addStudent(){
        Ext.Ajax.request ({
        url: 'inc/template.php',
        params: {action: 'submit_student',

                                 StudentFirst:firstNameTextField.getValue(),
                                 StudentLast:lastNameTextField.getValue(),
                                 StudentEmail: emailTextField.getValue(),
                                 StudentPhone:phoneNumberTextField.getValue(),
                                 StudentDOB:Ext.util.Format.date(dateOfBirth.getValue(), 'Y-m-d'),
                                 DateStarted:dateStarted.getValue(),
                                 LessonID:dayTypeCombo.getValue(),
                                 StudentAddress:streetTextField.getValue(),
                                 StudentCity:cityTextField.getValue(),
                                 StudentState:stateTextField.getValue(),
                                 StudentZip:zipTextField.getValue(),
                                 MusicInterest:musicInterest.getValue()
                                 },
                                 method: 'POST',
        });
    tabPanel.activate(studentGrid);
    tabPanel.activate(scheduleGrid);
    clearStudentForm();

我不知道为什么它只提交一次。真是莫名其妙。它显示了萤火虫的帖子。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

我不确定

AUTO-INCREMENT声明

alter table student add constraint StudentPK primary key AUTO_INCREMENT (StudentID);

我认为,您应该将此语法用于多个列。对于一列使用

CREATE TABLE student
(StudentID int NOT NULL PRIMARY KEY,
StudentFirst varchar(30),
...