0

我的 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;

和我的 EXTJ

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();

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

任何帮助深表感谢。

4

1 回答 1

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),
...
于 2013-04-25T13:29:05.100 回答