외래 키와 연결된 3 개의 테이블을 작업 중이며 ON UPDATE CASCADE
및 ON DELETE CASCADE
으로 설정하고 있습니다. 이 테이블은 category
, subcategory
및 products
입니다.외래 키 열을 포함하는 MySQL의 테이블을 업데이트하십시오.
products
테이블 - PID (PK), PRODUCTNAME, subcatid (FK)
subcategory
테이블 - subcatid (PK), subcategoryname, CATID (FK)
category
테이블 - CATID (PK), 범주
제품 이름을 변경하려면 UPDATE
제품 테이블에 대한 올바른 쿼리는 무엇입니까? 또한 양식을 사용하여 제품의 하위 범주를 변경하려는 경우?
제품 이름, 하위 범주 이름은 성공적으로 채워지지만 제품 테이블의 레코드는 업데이트되지 않으므로 아무 것도하지 않으며 제품 이름과 하위 범주 이름이 변경되지 않는 양식을 사용하고 있습니다.
도움을 주시면 감사하겠습니다.
는UPDATE products SET productname='New Name of Product' where PID=XXX;
트릭을 할 것 그렇게 간단한 표준, 다음 코드
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['PRODUCT_NAME'])) {
$pid = mysql_real_escape_string($_POST['thisPID']);
$catalog_no = mysql_real_escape_string($_POST['CATALOG_NO']);
$product_name = mysql_real_escape_string($_POST['PRODUCT_NAME']);
$price = mysql_real_escape_string($_POST['PRICE']);
$composition = mysql_real_escape_string($_POST['COMPOSITION']);
$size = mysql_real_escape_string($_POST['SIZE']);
$subcat = mysql_real_escape_string($_POST['SUBCAT_ID']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("UPDATE products SET CATALOG_N0='$catalog_no', PRODUCT_NAME='$product_name', PRICE='$price', COMPOSITION='$composition', SIZE='$size', SUBCAT_ID='$subcat' WHERE PID='$pid'");
header("location: inventory_list.php");
exit();
}
?>
<?php
// Gather this product's full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
$targetID = $_GET['pid'];
$sql = mysql_query("SELECT products.PID, products.CATALOG_NO, products.PRODUCT_NAME, products.PRICE, products.COMPOSITION, products.SIZE, products.SUBCAT_ID, subcategory.SUBCAT_ID, subcategory.SUBCATEGORY_NAME FROM (products, subcategory) WHERE subcategory.SUBCAT_ID=products.SUBCAT_ID AND PID='$targetID' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$catalog_no = $row["CATALOG_NO"];
$product_name = $row["PRODUCT_NAME"];
$price = $row["PRICE"];
$composition = $row["COMPOSITION"];
$size = $row["SIZE"];
$subcat = $row["SUBCAT_ID"];
}
} else {
echo "You dont have that product";
exit();
}
}
?>
양식과 함께 사용하려는 검색어는 무엇입니까? 그들을 게시하십시오. – Treffynnon
다음 코드 사용 – henry
코드로 질문을 업데이트하십시오. 댓글이 충분하지 않습니다. – Treffynnon