-1

我正在构建一个简单的表单来让用户请求供应,但在提交时它一直给我一个通用错误。我看不出我的错误在哪里...

     CREATE TABLE `teacherrequests` (
  `name` varchar(64) NOT NULL,
  `binder` varchar(3) NOT NULL,
  `binderpage` varchar(2) NOT NULL,
  `binderdiv` varchar(2) NOT NULL,
  `calcr` varchar(2) NOT NULL,
  `chalkcolor` varchar(2) NOT NULL,
  `chalkwhite` varchar(2) NOT NULL,
  `chalkeraser` varchar(2) NOT NULL,
  `colpencil` varchar(2) NOT NULL,
  `dryerasecleaner` varchar(2) NOT NULL,
  `dryeraser` varchar(2) NOT NULL,
  `dryerasemarkers` varchar(2) NOT NULL,
  `filefolders` varchar(2) NOT NULL,
  `gluesticks` varchar(2) NOT NULL,
  `hangingfile` varchar(2) NOT NULL,
  `highlightermulti` varchar(2) NOT NULL,
  `highlighterone` varchar(2) NOT NULL,
  `holepunch3` varchar(2) NOT NULL,
  `holepunch1` varchar(2) NOT NULL,
  `index35` varchar(2) NOT NULL,
  `index57` varchar(2) NOT NULL,
  `markers` varchar(2) NOT NULL,
  `papergraph` varchar(2) NOT NULL,
  `paperlegal` varchar(2) NOT NULL,
  `papersteno` varchar(2) NOT NULL,
  `paperwhitelined` varchar(2) NOT NULL,
  `paperclipsbindlg` varchar(2) NOT NULL,
  `paperclipsbindmd` varchar(2) NOT NULL,
  `paperclipsbindsm` varchar(2) NOT NULL,
  `paperclipslg` varchar(2) NOT NULL,
  `paperclipsmd` varchar(2) NOT NULL,
  `paperclipssm` varchar(2) NOT NULL,
  `pencil` varchar(2) NOT NULL,
  `pencilsharp` varchar(2) NOT NULL,
  `pensblack` varchar(2) NOT NULL,
  `pensblue` varchar(2) NOT NULL,
  `pensgreen` varchar(2) NOT NULL,
  `pensred` varchar(2) NOT NULL,
  `permanentmarker` varchar(2) NOT NULL,
  `postit` varchar(2) NOT NULL,
  `postitsmall` varchar(2) NOT NULL,
  `stapler` varchar(2) NOT NULL,
  `staples` varchar(2) NOT NULL,
  `tapedbl` varchar(2) NOT NULL,
  `tapemasking` varchar(2) NOT NULL,
  `tapescotch` varchar(2) NOT NULL,
  `tapedispenser` varchar(2) NOT NULL,
  `tacks` varchar(2) NOT NULL,
  `clock` varchar(2) NOT NULL,
  `whiteout` varchar(2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

这是代码...

我已经对照我的表格检查了这些,它们都匹配。

$name = $_POST['name'];
$binder = $_POST['binder'];
$binderpage = $_POST['binderpage'];
$binderdiv = $_POST['binderdiv'];
$calc = $_POST['calc'];
$chalkcolor = $_POST['chalkcolor'];
$chalkwhite = $_POST['chalkwhite'];
$chalkeraser = $_POST['chalkeraser'];
$colpencil = $_POST['colpencil'];
$dryerasecleaner = $_POST['dryerasecleaner'];
$dryeraser = $_POST['dryeraser'];
$dryerasemarkers = $_POST['dryerasemarkers'];
$filefolders = $_POST['filefolders'];
$gluesticks = $_POST['gluesticks'];
$hangingfile = $_POST['hangingfile'];
$highlightermulti = $_POST['highlightermulti'];
$highlighterone = $_POST['highlighterone'];
$holepunch3 = $_POST['holepunch3'];
$holepunch1 = $_POST['holepunch1'];
$index35 = $_POST['index35'];
$index57 = $_POST['index57'];
$markers = $_POST['markers'];
$papergraph = $_POST['papergraph'];
$paperlegal = $_POST['paperlegal'];
$papersteno = $_POST['papersteno'];
$paperwhitelined = $_POST['paperwhitelined'];
$paperclipsbindlg = $_POST['paperclipsbindlg'];
$paperclipsbindmd = $_POST['paperclipsbindmd'];
$paperclipsbindsm = $_POST['paperclipsbindsm'];
$pencil = $_POST['pencil'];
$pencilsharp = $_POST['pencilsharp'];
$pensblack = $_POST['pensblack'];
$pensblue = $_POST['pensblue'];
$pensgreen = $_POST['pensgreen'];
$pensred = $_POST['pensred'];
$permanentmarker = $_POST['permanentmarker'];
$postit = $_POST['postit'];
$postitsmall = $_POST['postitsmall'];
$stapleremover = $_POST['stapleremover'];
$stapler = $_POST['stapler'];
$staples = $_POST['staples'];
$tapedbl = $_POST['tapedbl'];
$tapemasking = $_POST['tapemasking'];
$tapescotch = $_POST['tapescotch'];
$tapedispenser = $_POST['tapedispenser'];
$tacks = $_POST['tacks'];
$clock = $_POST['clock'];
$whiteout = $_POST['whiteout'];

我假设我的错误在这里,但我似乎找不到它。

// Insert data into mysql 

$sql="INSERT INTO teacherrequests(name, binder, binderpage, binderdiv, calcr, 
chalkcolor, chalkwhite, chalkeraser, colpencil, dryerasecleaner, dryeraser,     
dryerasemarkers, filefolders, gluesticks, hangingfile, highlightermulti, highlighterone,     
holepunch3, holepunch1, index35, index57, markers, papergraph, paperlegal, papersteno,     
paperwhitelined, paperclipsbindlg, paperclipsbindmd, paperclipsbindsm, pencil,     
pencilsharp, pensblack, pensblue, pensgreen, pensred, permanentmarker, postit,     
postitsmall, stapleremover, stapler, staples, tapedbl, tapemasking, tapescotch,     
tapedispenser, tacks, clock, whiteout)

VALUES('$name', '$binder', '$binderpage',     
'$binderdiv', '$calc', '$chalkcolor', '$chalkwhite', '$chalkeraser', '$colpencil',     
'$dryerasecleaner', '$dryeraser', '$dryerasemarkers', '$filefolders', '$gluesticks',     
'$hangingfile', '$highlightermulti', '$highlighterone', '$holepunch3', '$holepunch1',     
'$index35', '$index57', '$markers', '$papergraph', '$paperlegal', '$papersteno',     
'$paperwhitelined', '$paperclipsbindlg', '$paperclipsbindmd', '$paperclipsbindsm',     
'$pencil', '$pencilsharp', '$pensblack', '$pensblue', '$pensgreen', '$pensred',     
'$permanentmarker', '$postit', '$postitsmall', '$stapleremover', '$stapler', '$staples',     
'$tapedbl', '$tapemasking', '$tapescotch', '$tapedispenser', '$tacks', '$clock',    
'$whiteout')";

$result=mysql_query($sql);

这是 var_dump:

ERRORstring(811) "INSERT INTO teacherrequests(name, binder, binderpage, binderdiv, calcr, chalkcolor, chalkwhite, chalkeraser, colpencil, dryerasecleaner, dryeraser, dryerasemarkers, filefolders, gluesticks, hangingfile, highlightermulti, highlighterone, holepunch3, holepunch1, index35, index57, markers, papergraph, paperlegal, papersteno, paperwhitelined, paperclipsbindlg, paperclipsbindmd, paperclipsbindsm, pencil, pencilsharp, pensblack, pensblue, pensgreen, pensred, permanentmarker, postit, postitsmall, stapleremover, stapler, staples, tapedbl, tapemasking, tapescotch, tapedispenser, tacks, clock, whiteout)VALUES('Joe Spano', '3', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '4', '', '', '', '', '', '2', '', '', '', '', '', '', '', '', '', '5', '', '', '', '', '', '', '', '')"
4

2 回答 2

14

你应该做的第一件事就是把这个数据库设计扔进垃圾桶。然后用这个设计替换它:

CREATE TABLE teachingmaterials (
    id SMALLINT NOT NULL AUTO_INCREMENT,
    name VARCHAR(64) NOT NULL,
    PRIMARY KEY (id)
) ENGINE=INNODB CHARACTER SET utf8;

INSERT INTO
    teachingmaterials
    (name)
VALUES
    ('binder'),
    ('binder-page'),
    ('binder-div'),
    -- put the rest of them in here --
    ('whiteout');

CREATE TABLE teacherrequests (
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR(64) NOT NULL,
    PRIMARY KEY (id)
) ENGINE=INNODB CHARACTER SET utf8;

CREATE TABLE teacherrequests_teachingmaterials (
    teacherrequests_id INT NOT NULL,
    teachingmaterials_id SMALLINT NOT NULL,
    amount SMALLINT,
    note VARCHAR(64),
    PRIMARY KEY (teacherrequests_id, teachingmaterials_id)
    FOREIGN KEY (teacherrequests_id) REFERENCES teacherrequests (id) ON DELETE CASCADE,
    FOREIGN KEY (teachingmaterials_id) REFERENCES teachingmaterials (id)
) ENGINE=INNODB CHARACTER SET utf8;

您还需要停止使用旧mysql_*功能并改用 PDO。

于 2012-05-01T18:31:05.830 回答
7

看一眼

 `calcr` varchar(2) NOT NULL,

在您的创建表代码上与

$calc = $_POST['calc'];

在你的 php 代码中。我猜这只是一个简单的错字,最后多了一个“r”。

我还发现这些代码行在另一个文件中没有附带的行:

  `paperclipslg` varchar(2) NOT NULL,
  `paperclipsmd` varchar(2) NOT NULL,
  `paperclipssm` varchar(2) NOT NULL,

  $stapleremover = $_POST['stapleremover'];

希望有帮助!

[编辑]不过,我没有看到您的插入内容和您的值之间有任何差异。所以现在我看多了,我不认为我已经帮助解决了这个问题。我只找到了一些您可能丢失的数据。

于 2012-05-01T18:13:39.463 回答