Databases Reference
In-Depth Information
{
$gift_id=$row["gift_id"];
// Update an existing gift if there is corresponding data
// submitted from the form
if(
isset($_POST["quantity" ][$gift_id]) &&
isset($_POST["description"][$gift_id]) &&
isset($_POST["color" ][$gift_id]) &&
isset($_POST["shop" ][$gift_id]) &&
isset($_POST["price" ][$gift_id])
)
update_or_insert_gift_data($connection, $gift_id);
}
// Process the data submitted in the form fields for the new
// gift; we had assigned this the index 0 in the HTML form.
update_or_insert_gift_data($connection, 0);
}
// Update the data for a gift with the specified gift ID; for a
// gift ID of 0, add a new gift to the database.
function update_or_insert_gift_data($connection, $gift_id)
{
// Extract the data items for the gift attributes from the $_POST array
$quantity =clean($_POST["quantity" ][$gift_id], 5);
$description=clean($_POST["description"][$gift_id], 255);
$color =clean($_POST["color" ][$gift_id], 30);
$shop =clean($_POST["shop" ][$gift_id], 100);
$price =clean($_POST["price" ][$gift_id], 30);
// If the gift_id is 0, this is a new gift, so set the
// gift_id to be empty; MySQL will automatically assign a
// unique gift_id to the new gift.
if($gift_id==0)
$gift_id='';
// If any of the attributes are empty, don't update the database.
if(
!strlen($quantity ) ||
!strlen($description) ||
!strlen($color ) ||
!strlen($shop ) ||
!strlen($price )
)
{
// If this isn't the blank row for optionally adding a new gift,
// or if it is the blank row and the user has actually typed
// something in, display an error message.
if(!empty($gift_id)
||
strlen(
$quantity.
$description.
 
Search WWH ::




Custom Search