MANAGING CONTENT Although there are five columns in (Most popular web site)
MANAGING CONTENT Although there are five columns in the journal table, the INSERT command needs values for only three; the primary key and the updated columns are filled automatically by MySQL. As explained earlier, text values must be in quotes in SQL queries, so $title and $article are enclosed in single quotes. The whole query is enclosed in double quotes to ensure that the variables are processed. The value for the created column is generated by a MySQL function, NOW(), which generates a current timestamp. In the update query later, this column remains untouched, preserving the original date and time. 4. Finally, you submit the query, using mysql_query(). If the query is processed successfully, you redirect the page to a list of existing records. Add the following code: // process the query $result = mysql_query($sql) or die(mysql_error()); // if successful, redirect to list of existing records if ($result) { header(’Location: http://localhost/phpsolutions/admin/ . journal_list.php’); exit; } } ?> There s nothing new about this last section of code. Before testing the page, you need to build journal_list.php, which is described in PHP Solution 13-4. PHP Solution 13-2: Inserting a new record with MySQL Improved Use journal_insert01.php in the download files. The finished code is in journal_insert_mysqli.php. 1. The code that inserts a new record should be run only if the form has been submitted, so it s enclosed in a conditional statement that checks for the name attribute of the submit button (insert) in the $_POST array. Put the following above the DOCTYPE declaration: 353
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.