0

现在我有这样的部分代码:

$q_ins='INSERT INTO `TOF_ARTICLES` VALUES (''.$r['ART_ID'].'',''.$r['ART_ARTICLE_NR'].'',''.$r['ART_SUP_ID'].'',''.$r['ART_DES_ID'].'',''.$r['ART_COMPLETE_DES_ID'].'',''.$r['ART_CTM'].'',''.$r['ART_PACK_SELFSERVICE'].'',''.$r['ART_MATERIAL_MARK'].'',''.$r['ART_REPLACEMENT'].'',''.$r['ART_ACCESSORY'].'',''.$r['ART_BATCH_SIZE1'].'',''.$r['ART_BATCH_SIZE2'].'');';

但是php说:

解析错误:语法错误,第 40 行 X:\denwer\www\denwer\td.php 中的意外 T_STRING

怎么了?我理解有语法的东西,但是什么?以及如何正确?

4

6 回答 6

5

使用这个更新的查询

$q_ins="INSERT INTO `TOF_ARTICLES` VALUES ('".$r['ART_ID']."','".$r['ART_ARTICLE_NR']."','".$r['ART_SUP_ID']."','".$r['ART_DES_ID']."','".$r['ART_COMPLETE_DES_ID']."','".$r['ART_CTM']."','".$r['ART_PACK_SELFSERVICE']."','".$r['ART_MATERIAL_MARK']."','".$r['ART_REPLACEMENT']."','".$r['ART_ACCESSORY']."','".$r['ART_BATCH_SIZE1']."','".$r['ART_BATCH_SIZE2']."');";
于 2012-07-16T16:28:08.607 回答
4

对于初学者来说,你真的不应该做你正在做的事情。使用非参数化查询是极其危险的。

但要回答你的问题,试试这个。

$q_ins= "INSERT INTO `TOF_ARTICLES` VALUES ('{$r['ART_ID']}','{$r['ART_ARTICLE_NR']}','{$r['ART_SUP_ID']}','{$r['ART_DES_ID']}','{$r['ART_COMPLETE_DES_ID']}','{$r['ART_CTM']}','{$r['ART_PACK_SELFSERVICE']}','{$r['ART_MATERIAL_MARK']}','{$r['ART_REPLACEMENT']}','{$r['ART_ACCESSORY']}','{$r['ART_BATCH_SIZE1']}','{$r['ART_BATCH_SIZE2']}');";
于 2012-07-16T16:29:59.097 回答
1
$q_ins = <<<MySQL
INSERT INTO `TOF_ARTICLES`
VALUES (
  {$r["ART_ID"]}
  ,{$r["ART_ARTICLE_NR"]}
  ,{$r["ART_SUP_ID"]}
  ,{$r["ART_DES_ID"]}
  ,{$r["ART_COMPLETE_DES_ID"]}
  ,{$r["ART_CTM"]}
  ,{$r["ART_PACK_SELFSERVICE"]}
  ,{$r["ART_MATERIAL_MARK"]}
  ,{$r["ART_REPLACEMENT"]}
  ,{$r["ART_ACCESSORY"]}
  ,{$r["ART_BATCH_SIZE1"]}
  ,{$r["ART_BATCH_SIZE2"]}
  )
;
MySQL;

那里,不是更好吗?

于 2012-07-16T16:32:45.943 回答
1

尝试这个 :

$q_ins='INSERT INTO `TOF_ARTICLES` VALUES ("'.$r['ART_ID'].'","'.$r['ART_ARTICLE_NR'].'","'.$r['ART_SUP_ID'].'","'.$r['ART_DES_ID'].'","'.$r['ART_COMPLETE_DES_ID'].'","'.$r['ART_CTM'].'","'.$r['ART_PACK_SELFSERVICE'].'","'.$r['ART_MATERIAL_MARK'].'","'.$r['ART_REPLACEMENT'].'","'.$r['ART_ACCESSORY'].'","'.$r['ART_BATCH_SIZE1'].'","'.$r['ART_BATCH_SIZE2'].'");';
于 2012-07-16T16:27:28.767 回答
1

您的代码插入似乎有一对多的“”:P

'.$r['ART_COMPLETE_DES_ID'].''替换为 '.$r["ART_COMPLETE_DES_ID"].'' 以免混淆。

这是一个完整的查询:

mysql_query("

INSERT INTO `TOF_ARTICLES` 
(`art_id`, 
`art_article_nr`, 
`art_sup_id`, 
`art_des_id`, 
`art_complete_des_id`, 
`art_ctm`, 
`art_pack_selfservice`, 
`art_material_mark`, 
`art_replcacement`, 
`art_accessory`, 
`art_batch_size1`, 
`art_batch_size2`)

VALUES (''.$r['ART_ID'].'',
''.$r['ART_ARTICLE_NR'].'',
'".$r['ART_SUP_ID']."',
''.$r['ART_DES_ID'].'',
''.$r['ART_COMPLETE_DES_ID'].'',
''.$r['ART_CTM'].'',
''.$r['ART_PACK_SELFSERVICE'].'',
''.$r['ART_MATERIAL_MARK'].'',
''.$r['ART_REPLACEMENT'].'',
''.$r['ART_ACCESSORY'].'',
''.$r['ART_BATCH_SIZE1'].'',
''.$r['ART_BATCH_SIZE2'].'');
") or die("Error: " . mysql_error());
于 2012-07-16T16:28:42.390 回答
0

这可能是你的报价。尝试这个:

$q_ins = 'INSERT INTO `TOF_ARTICLES` VALUES ('.$r['ART_ID'].',
                                             '.$r['ART_ARTICLE_NR'].',
                                             '.$r['ART_SUP_ID'].',
                                             '.$r['ART_DES_ID'].',
                                             '.$r['ART_COMPLETE_DES_ID'].',
                                             '.$r['ART_CTM'].',
                                             '.$r['ART_PACK_SELFSERVICE'].',
                                             '.$r['ART_MATERIAL_MARK'].',
                                             '.$r['ART_REPLACEMENT'].',
                                             '.$r['ART_ACCESSORY'].',
                                             '.$r['ART_BATCH_SIZE1'].',
                                             '.$r['ART_BATCH_SIZE2'].')';
于 2012-07-16T16:29:51.343 回答