【发布时间】:2011-05-30 17:05:08
【问题描述】:
我正在尝试使用 PHP 将数据添加到 3 个表中,atm 我只能查看加入的表的结果。
结果查询
$sql = mysql_query("SELECT PART_ID, PART_DESC, SERIAL_NUM, PART.RACK_NUM, PART.PART_TYPE_ID, PART_TYPE_DESC, LOCATION
FROM PART
INNER JOIN PART_TYPE ON PART.PART_TYPE_ID = PART_TYPE.PART_TYPE_ID
INNER JOIN RACK ON RACK.RACK_NUM = PART.RACK_NUM
这将从 PART 表中获取所有行,并且对于我们找到的每一行,将该行与 PART_TYPE 表中的一行匹配(条件是它们具有相同的 PART_TYPE_ID)。如果在 PART 表中的给定行中找不到 PART 和 PART_TYPE 表之间的匹配项,则该行将不会包含在结果中。
我的插入查询这是我遇到问题的地方
如何将数据添加到 PART_ID、PART_TYPE 和 RACK 表中?
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['PART_ID'])) {
$id = mysql_real_escape_string($_POST['PART_ID']);
$PART_DESC = mysql_real_escape_string($_POST['PART_DESC']);
$SERIAL_NUM = mysql_real_escape_string($_POST['SERIAL_NUM']);
$RACK_NUM = mysql_real_escape_string($_POST['RACK_NUM']);
$PART_TYPE_ID = mysql_real_escape_string($_POST['PART_TYPE_ID']);
$LOCATION = mysql_real_escape_string($_POST['LOCATION']);
$PART_TYPE_DESC = mysql_real_escape_string($_POST['PART_TYPE_DESC']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT PART_ID FROM PART WHERE PART_ID='$id' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 0) {
echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>';
exit();
}
// Add this product into the database now
**$sql = mysql_query("INSERT INTO PART (PART_ID, PART_DESC, SERIAL_NUM, RACK_NUM, PART_TYPE_ID)
VALUES('$id','$PART_DESC','$SERIAL_NUM','$RACK_NUM','$PART_TYPE_ID')") or die (mysql_error());**
header("location: inventory_list.php");
exit();
}
?>
【问题讨论】:
-
那么您的问题是什么或问题出在哪里?
-
这是一种奇怪的查询方式.. 使用 PDO
-
@yes 123 有没有更有效的方法?
-
是的,使用 pdo php.net/manual/en/pdo.prepare.php
-
向非管理员用户discloses too much information输出数据库错误。