I have a custom view defined that takes fields from two different tables.
I want the user to edit those fields using the Custom View Edit Record page.
Then, for saving, I have a script to write the correct fields to each table.
I'm having trouble extracting the new input data from the customer and passing it along to write to the different tables.
Here's what I have:
The Query for the Custom View (note, the key column is set for product_id) :
SELECT
bbw_product.product_id,
bbw_product.quantity,
bbw_product.price,
bbw_product.status,
bbw_product_description.name,
bbw_product_description.description
FROM bbw_product
INNER JOIN bbw_product_description ON bbw_product.product_id = bbw_product_description.product_id
On the Custom View Edit Page, I have a PHP snippet:
global $conn;
global $data;
if (isset($_POST['S3'])) {
// update fields
// update name into product_description_table, using product_id
$pid = $data['product_id'];
// update data into product table
$sql = "UPDATE bbw_product SET ";
$sql .= "price = '" . $values["price"]."'";
$sql .= ", quantity='" . $values["quantity"]."'";
$sql .= ", status='" . $data['status']."'";
$sql .= ", minimum='" . $data['minimum']."'";
$sql .= ", maximum='" . $data['maximum']."'";
$sql .= " WHERE product_id = '" . $pid ."'";
echo $sql;
if (!mysqli_query($conn,$sql)) {
echo "Error: " . $sql . "
" . mysqli_error($conn);
return false;
}
// update name into product_description_table, using product_id
$sql = "UPDATE bbw_product_description SET ";
$sql .= "name = '" . $data['name']."'";
$sql .= ",description='" . $data['description']."'";
$sql .= " WHERE product_id = '" . $pid ."'";
echo "
".$sql;
if (!mysqli_query($conn,$sql)) {
echo "Error: " . $sql . "
" . mysqli_error($conn);
return false;
}
$message = "SUCCESS: Tables Updated";
return false;
}
?>
// this is the 'Save' button
//
// this is pared down to have just two fields, name and quantity
//
<form action="" method="post">
Name: <input type="text" name="name" value="<?php echo $data['name']; ?>" \>
Quantity: <input type="text" name="quantity" value="<?php echo $data['quantity'];?>" \>
<input type="submit" value="Save" id="S3" name="S3" \>
</form>
<?php
The trouble is, the values the user types in are not getting passed to the UPDATE statement.
I don't know whether I should use $values, $data, $_POST, or something else...
Please advise.