mysql_query($sql, $conn) or die( Could not remove article; (Web server version)
mysql_query($sql, $conn) or die( Could not remove article; . mysql_error()); } redirect( cpanel.php ); break; } } else { redirect( index.php ); } ?> How It Works Want to look at some more code? Great! Let s take a look at transact-article.php. This time, we ll simply point out some of the more interesting things we might not have covered yet, or things that bear repeating. Yes, this bears repeating. You know what the following does, right? It registers the session variables that invariably will need to be set in order to run some of these transactions. This gives you access to the data for the currently logged-in user: session_start(); The transact-article.php page requires connection to the database, and redirects users to various pages using the redirect() function. The following two include files provide this functionality, respectively. require_once conn.php ; require_once http.php ; You need to make sure that a button was pressed, or an action is specified in the URL (such as ?action= twiddleThumbs). if (isset($_REQUEST[ action ])) { A lot of actions can happen in this file. The switch() statement is a more elegant way of choosing your transactions than if/else. switch ($_REQUEST[ action ]) { You first ensure that the title and body were both entered and that the user is logged in (tested by the presence of the user_id session variable). case Submit New Article : if (isset($_POST[ title ]) and isset($_POST[ body ]) and isset($_SESSION[ user_id ])) { You insert the article into the database, including the user ID and the date. The datetime is formatted in a standard MySQL datetime format that can be stored in a datetime column. When you retrieve that 440 Chapter 13
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.