0

操作数应包含 1 列

我的代码有什么问题,这意味着我尝试通过选择插入到活动笔记表中

<?php
   require_once('Connections/Thaymay.php');
   mysql_select_db($database_Thaymay, $Thaymay);   
   $activityid = $_POST['select'];

  if($_POST) {
    foreach($_POST['namebox'] as $check) {

            echo "$check \n "; 
            echo "<br> ";


            $query_ReSeActi = " INSERT INTO `ph3`.`activitynote` ( `idmemberref`, `idactivity`, `manaferid`, `staffinput`) select ( 
            idmemberref,    $activityid,    manaferid,  'system'  ) from activitynote where id = $check ;    ";
            $RsActivitynoteMem = mysql_query($query_ReSeActi, $Thaymay) or die(mysql_error());

    }
}



?>
4

2 回答 2

0
<?php
   require_once('Connections/Thaymay.php');
   mysql_select_db($database_Thaymay, $Thaymay);

   $activityid = $_POST['select'];

  if($_POST) {
    foreach($_POST['namebox'] as $check) {


            echo "$check \n "; 
            echo "<br> ";


            $query_ReSeActi = "
INSERT INTO `ph3`.`activitynote` 
( `idmemberref`
, `idactivity`
, `manaferid`
, `staffinput`
, `dateadd`
)
SELECT
  idmemberref
, $activityid
, manaferid
, 'system'
, NOW() 
FROM activitynote 
WHERE id = $check
"
;

$RsActivitynoteMem = mysql_query($query_ReSeActi, $Thaymay) or die(mysql_error());
    }
}
echo "<br><br> ";
echo $_POST['select'];



?>
于 2011-12-28T02:07:15.143 回答
0

如果您期望 $_POST['namebox'] 有多个值,您可能希望在一个查询中而不是在循环中完成所有操作(一般来说,如果您可以保存到数据库的行程,您应该作为到数据库的往返行程通常是相当昂贵的操作)。像这样的东西可能会起作用,对您的 POST 输入进行一些额外的清理:

$idArray = array();  
if($_POST) {
  if( is_array( $_POST['namebox'] ) ) {
     foreach($_POST['namebox'] as $check) {
       $cleanCheck = intval( $check );
       if( $check > 0 ) {
          $idArray[] = $check;
       }
     }
  }
  $query_ReSeActi = " INSERT INTO `ph3`.`activitynote` ( `idmemberref`, `idactivity`, `manaferid`, `staffinput`) select ( 
        idmemberref,    $activityid,    manaferid,  'system'  ) from activitynote where id IN (" . implode( ',', $idArray ) . ") ;    ";
        $RsActivitynoteMem = mysql_query($query_ReSeActi, $Thaymay) or die(mysql_error());

}

这假设您的 $_POST['namebox'] 正在将整数 ID 传递给您的脚本。

于 2011-12-27T13:11:31.660 回答