PHP,MYSQL记录不插入

时间:2012-05-08 13:00:31

标签: php mysql

我有两个mysql表:

--
-- Table structure for table `body`
--

DROP TABLE IF EXISTS `body`;
CREATE TABLE IF NOT EXISTS `body` (
`bChar` bigint(10) NOT NULL,
`bPart` bigint(10) NOT NULL,
`bStr` int(3) NOT NULL,
`bDur` int(3) NOT NULL,
`bItem` bigint(10) NOT NULL,
`bHealth` int(3) NOT NULL,
`bSpd` int(3) NOT NULL,
`bMaxDur` int(3) NOT NULL,
`bCurse` int(1) NOT NULL,
`bAct` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Table structure for table `partybody`
--

DROP TABLE IF EXISTS `partybody`;
CREATE TABLE IF NOT EXISTS `partybody` (
`pabChar` bigint(10) NOT NULL,
`pabPart` bigint(10) NOT NULL,
`pabStr` int(3) NOT NULL,
`pabDur` int(3) NOT NULL,
`pabItem` int(10) NOT NULL,
`pabHealth` int(3) NOT NULL,
`pabAct` int(1) NOT NULL,
`pabNum` int(4) NOT NULL,
`pabSlot` int(1) NOT NULL,
`pabSpd` int(3) NOT NULL,
`pabMaxDur` int(3) NOT NULL,
`pabCurse` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

以下是正文中的数据:

(0, 25, 0, 0, 0, 120, 0, 0, 0, 1)   

我有这个PHP代码:

$query = "SELECT * FROM body WHERE bChar = ".$_SESSION['chNum'];
$result2 = mysql_query($query, $_SESSION['connect']) or die("Error 3:".mysql_error());
while($row2 = mysql_fetch_array($result2)) {
   query = "INSERT INTO partybody VALUES(".$_SESSION['chNum'].",".$row2['bPart'].",".$row2['bStr'].",".$row2['bDur'].",".$row2['bItem'].",".$row2['bHealth'].",1,1,1,".$row2['bSpd'].",".$row2['bMaxDur'].",".$row2['bCurse'].")";
  mysql_query($query, $_SESSION['connect']) or die("Error 4a:".mysql_error());
}

我刚刚将$row2['bCurse']添加到INSERT,我将错误消息从错误4更改为错误4a:但是当我执行程序时,我得到了这个:

Error 4:Column count doesn't match value count at row 1. 

我尝试清除缓存,但这没有帮助。想法?

1 个答案:

答案 0 :(得分:0)

如果仍然只使用测试数据填充数据库,则可以输出所有查询字符串,并在视觉上检查是否有可能发生故障。查找可能看起来像number,,number的查询部分。

$query = "SELECT * FROM body WHERE bChar = ".$_SESSION['chNum'];
var_dump($query);
$result2 = mysql_query($query, $_SESSION['connect']) or die("Error 3:".mysql_error());
while($row2 = mysql_fetch_array($result2)) {
   query = "INSERT INTO partybody VALUES(".$_SESSION['chNum'].",".$row2['bPart'].",".$row2['bStr'].",".$row2['bDur'].",".$row2['bItem'].",".$row2['bHealth'].",1,1,1,".$row2['bSpd'].",".$row2['bMaxDur'].",".$row2['bCurse'].")";
   var_dump($query)
   //mysql_query($query, $_SESSION['connect']) or die("Error 4a:".mysql_error());
}

BTW是query前面错误的美元符号?

query = "INSERT INTO partybody VALUES(".$_SESSION['chNum'].",".$row2['bPart'].",".$row2['bStr'].",".$row2['bDur'].",".$row2['bItem'].",".$row2['bHealth'].",1,1,1,".$row2['bSpd'].",".$row2['bMaxDur'].",".$row2['bCurse'].")";