Helping ordinary people create extraordinary websites!

Web Database Access from Desktop Applications

By Michael J. Ross
2008-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:
 4 Votes

You might also want to check these out:


Leave a Comment on "Web Database Access from Desktop Applications"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS