J'essaie de mettre à jour une base de données en utilisant un formulaire, mais ce n'est pas en ajoutant l'élément ou la mise à jour. La suppression de l'élément fonctionne mais c'est tout. Qu'est-ce que je fais de mal et comment puis-je faire pour résoudre ce problème?PHP/MYSQL Comment insérer/mettre à jour plusieurs tables
Merci d'avance votre aide est appréciée.
INSERT ARTICLE PAGE
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['PART_DESC'])) {
$PART_DESC = $row["PART_DESC"];
$SERIAL_NUM = $row["SERIAL_NUM"];
$RACK_NUM = $row["RACK_NUM"];
$PART_TYPE_ID = $row["PART_TYPE_ID"];
$PART_TYPE_DESC = $row["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' 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.php">click here</a>';
exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO PART (PART_DESC, SERIAL_NUM, RACK_NUM, PART_TYPE_DESC, LOCATION)
VALUES('$PART_DESC','$SERIAL_NUM','$RACK_NUM','$PART_TYPE_ID','$PART_TYPE_DESC',now())") or die (mysql_error());
$pid = mysql_insert_id();
exit();
}
?>
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
EDIT PAGE ARTICLE
<?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 PART_ID, PART_DESC, SERIAL_NUM, RACK.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
WHERE PART_ID='$targetID' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["PART_ID"];
$PART_DESC = $row["PART_DESC"];
$SERIAL_NUM = $row["SERIAL_NUM"];
$RACK_NUM = $row["RACK_NUM"];
$PART_TYPE_ID = $row["PART_TYPE_ID"];
$PART_TYPE_DESC = $row["PART_TYPE_DESC"];
$LOCATION = $row["LOCATION"];
}
} else {
echo "Sorry dude that crap dont exist.";
exit();
}
}
?>
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['PART_DESC'])) {
$pid = mysql_real_escape_string($_POST['thisID']);
$PART_DESC = $row["PART_DESC"];
$SERIAL_NUM = $row["SERIAL_NUM"];
$RACK_NUM = $row["RACK_NUM"];
$PART_TYPE_ID = $row["PART_TYPE_ID"];
$PART_TYPE_DESC = $row["PART_TYPE_DESC"];
$LOCATION = $row["LOCATION"];
// See if that product name is an identical match to another product in the system
$sql = mysql_query("UPDATE PART SET PART_DESC='$PART_DESC', SERIAL_NUM='$SERIAL_NUM', PART.PART_TYPE_DESC='$PART_TYPE_DESC', RACK.RACK_NUM='$RACK_NUM', LOCATION='$LOCATION'
INNER JOIN PART_TYPE ON PART.PART_TYPE_ID = PART_TYPE.PART_TYPE_ID
INNER JOIN RACK ON RACK.RACK_NUM = PART.RACK_NUM WHERE PART.PART_ID='$pid'");
header("location: inventory.php");
exit();
}
>
Vous devriez ajouter le 'ou mourir (mysql_error());' pour la mise à jour, et voir pourquoi il n'est pas mis à jour. Vous devriez aussi lancer l'ID de l'intérieur vers l'INT ou l'échapper aussi. –
ne voulez-vous pas faire: '$ PART_DESC = mysql_real_escape_string ($ row [" PART_DESC "]);' ou ces données proviennent-elles de votre base de données? – Johan
il vient de la base de données –