-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 に答える