我查看了许多不同的站点,包括 php.net,但仍然没有发现为什么我的插入脚本不起作用。我正在使用 Eclipse 在 PHP 中进行编程,并且我安装了 PHP 插件以便它可以正常工作,但我还没有弄清楚我的脚本有什么问题。
前任。
switch($type) {
case(1):
require("opendb.php");
$query = "INSERT INTO ability(AbilityName,Description,Strength,Defense,Luck,Agility) values ('" . $name . '","' . $description . '","' . $strength . '","' . $defense . '","' . $luck . '","' . $agility . "')";
if (!mysql_query($query)) {
echo "Ability was not entered successfully: " . mysql_error();
} else {
echo "Ability was entered successfully!";
}
break;
case(2):
require("opendb.php");
$query = "INSERT INTO weapon(WeaponName,Description,Strength,Defense,Luck,Agility) values ('" . $name . '","' . $description . '","' . $strength . '","' . $defense . '","' . $luck . '","' . $agility . "')";
if (!mysql_query($query)) {
echo "Weapon was not entered successfully: " . nysql_error();
} else {
echo "Weapon was entered successfully!";
}
break;
default:
require("opendb.php");
$query = "INSERT INTO item(ItemName,Description,Strength,Defense,Luck,Agility) values ('" . $name . '","' . $description . '","' . $strength . '","' . $defense . '","' . $luck . '","' . $agility . "')";
if (!mysql_query($query)) {
echo "Item was not entered successfully: " . mysql_error();
} else {
echo "Item was entered successfully!";
}
}
}
您应该能够选择单选按钮以将对象插入为项目、武器或能力,但我不断收到列值与行值计数错误不匹配。这是我创建的三个表。每次输入对象时,ID 都会自动递增。它不为空,但我不需要在用于输入对象的表单中包含 ID。
物品表:
ItemID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
ItemName varchar(40),
Description longtext,
Strength INT NOT NULL,
Defense INT NOT NULL,
Luck INT NOT NULL,
Agility INT NOT NULL
武器表:
WeaponID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
WeaponName varchar(40),
Description longtext,
Strength INT NOT NULL,
Defense INT NOT NULL,
Luck INT NOT NULL,
Agility INT NOT NULL
能力表:
AbilityID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
AbilityName varchar(40),
Description longtext,
Strength INT NOT NULL,
Defense INT NOT NULL,
Luck INT NOT NULL,
Agility INT NOT NULL