Archive for the 'MYSQL5' Category

MANAGING CONTENT // create database (Web hosting domain names) connection $conn =

Tuesday, June 10th, 2008

MANAGING CONTENT // create database connection $conn = dbConnect(’admin’); // get details of selected record if (isset($_GET[’article_id’]) && !$_POST) { // prepare SQL query $sql = ‘SELECT article_id, title, article FROM journal WHERE article_id = ?’; // initialize statement $stmt = $conn->stmt_init(); if ($stmt->prepare($sql)) { // bind the query parameters $stmt->bind_param(’i', $_GET[’article_id’]); // bind the results to variables $stmt->bind_result($article_id, $title, $article); // execute the query, and fetch the result $OK = $stmt->execute(); $stmt->fetch(); } } // redirect if $_GET[’article_id’] not defined if (!isset($_GET[’article_id’])) { header(’Location: http://localhost/phpsolutions/admin/ . journal_list.php’); exit; } // display error message if query fails if (isset($stmt) && !$OK && !$done) { echo $stmt->error; } ?> Although this is very similar to the code used for the insert page, the first few lines are outside the conditional statements. Both stages of the update process require the include files, the removal of backslashes, and the database connection, so this avoids the need to duplicate the same code later. Two flags are initialized: $OK to check the success of retrieving the record, and $done to check whether the update succeeds. The first conditional statement makes sure that $_GET[’article_id’] exists and that the $_POST array is empty. So the code inside the braces is executed only when the query string is set, but the form hasn t been submitted. You prepare the SELECT query in the same way as for an INSERT command, using a question mark as a placeholder for the variable. However, note that instead of using an asterisk to retrieve all columns, the query specifies three columns by name like this: $sql = ‘SELECT article_id, title, article FROM journal WHERE article_id = ?’; 365
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Free web host - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY //

Monday, June 9th, 2008

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY // prepare the SQL query $sql = “UPDATE journal SET title = ‘$title’, article = ‘$article’ WHERE article_id = $article_id”; // submit the query $done = mysql_query($sql) or die(mysql_error()); } // redirect page on success or $article_id is invalid if ($done || !isset($article_id)) { Most of this code should be familiar. Any backslashes inserted by magic quotes will have been removed by nukeMagicQuotes() because you placed it outside the conditional statements in step 1, so this code block begins by passing items in the $expected array to mysql_real_escape_string() to prepare them for insertion into the database, and storing them in shorter variables ($title, $article, and $article_id). Because it s possible to tamper with a hidden field, you make sure that $article_id is numeric before carrying on. In the UPDATE query, strings need to be quoted, so the entire query is enclosed in double quotes, with $title and $article in single quotes. Although the mysql_query() function returns a result set from a SELECT query, with UPDATE, it returns true or false. So, if the update succeeds, $done is reset to true. You need to add $done || to the condition that controls the page redirection script. This redirects the page either if $done is true or if $article_id is invalid. 8. Save journal_update.php and test it by loading journal_list.php, selecting one of the EDIT links, and making changes to the record that is displayed. When you click Update record, you should be taken back to journal_list.php. You can verify that your changes were made by clicking the same EDIT link again. Check your code, if necessary, with journal_update_mysql02.php. PHP Solution 13-6: Updating a record with MySQL Improved Use journal_update01.php fromthe download files. The code for the first stage of the update process is in journal_update_mysqli01php, and the final code is in journal_update_mysqli02.php. 1. The first stage involves retrieving the details of the record that you want to update. Put the following code above the DOCTYPE declaration: Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

MANAGING CONTENT The Update entry button (Top ten web hosting) doesn t do

Sunday, June 8th, 2008

MANAGING CONTENT The Update entry button doesn t do anything yet. Just make sure that everything is displayed correctly, and confirm that the primary key is registered in the hidden field. You can check your code, if necessary, against journal_update_mysql01.php. Figure 13-4. An update form uses the primary key to retrieve and display a record ready for editing. 7. The name attribute of the submit button is update, so all the update processing code needs to go in a conditional statement that checks for the presence of update in the $_POST array. Place the code highlighted in bold just before the page redirect script: $row = mysql_fetch_assoc($result); } // if form has been submitted, update record if (array_key_exists(’update’, $_POST)) { // prepare expected items for insertion into database foreach ($_POST as $key => $value) { if (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } // abandon the process if primary key invalid if (!is_numeric($article_id)) { die(’Invalid request’); } 363
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY (Best web hosting) The

Thursday, June 5th, 2008

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The final conditional statement redirects the page to journal_list.php if $article_id was set to NULL earlier. A variable that has been set to NULL is considered unset, so !isset($article_id) returns true if $article_id is NULL. 2. Now that you have retrieved the contents of the record, you need to display them in the update form by using PHP to populate the value attribute of each input field. Before doing so, it s a good idea to check that you actually have something to display. If someone changes the value of article_id in the query string, you may get an empty result set, so there is no point in going any further. Add the following conditional statement immediately before the opening

tag:

List all entries


Invalid request: record does not exist.


If $row contains no values, empty($row) returns true and displays the warning message. The form is wrapped in the else clause and is displayed only if the query finds a valid record to be updated. Add the closing curly brace of the else clause immediately after the closing

tag like this:

3. If $row isn t empty, you can display the results of the query without further testing. However, you need to pass text values to htmlentities() to avoid any problems with the display of quotes. Change the code in the title input field like this: Make sure there is no space between the opening and closing PHP and