Web Database Access from Desktop Applications
By Michael J. Ross2008-05-06
Database Updating
Up to this point, we have seen how to read data from a remote database. But what if you need to modify data within that database? The same technique can be used, as illustrated in the expanded version of the PHP script below:
require_once 'SQL_functions.php';
if ( ! isset( $_GET[ 'registration_number' ] ) ) {
exit( 'Error: required parameter registration_number is missing' );
}
if ( isset( $_GET[ 'expiration_date' ] ) ) {
$query = SQL_query( 'UPDATE product_registration
SET expiration_date = "' . $_GET[ 'expiration_date' ]
. '" WHERE registration_number = ' . $_GET[ 'registration_number' ] );
if ( ! $query_okay ) {
echo 'Expiration date updated';
}
else {
exit( 'Error: invalid registration_number passed' );
}
}
else {
list( $query_okay, $expiration_date ) = SQL_query( 'SELECT expiration_date
FROM product_registration WHERE registration_number = '
. $_GET[ 'registration_number' ] );
if ( ! $query_okay ) {
exit( 'Error: invalid registration_number passed' );
}
echo $expiration_date;
}
?>
For example, if you want to add another month to Jane's license, the
following URL would work:
http://www.example.com/product_expiration_date.php?
registration_number=1&expiration_date=2008-06-30
Tutorial Pages:
» Web Database Access from Desktop Applications
» Sample Database
» Database Access Script
» Desktop Application Access
» Database Updating
» Conclusion
