Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2009, 01:31 PM
Registered User
 
Join Date: Oct 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default CH 13 some errors solved

was not able to find exact problem with composing articles so i downloaded code for ch 13 of previous book and made appropriated changes for database of this book. following code for cms_transact_article works so far:

<?php
session_start();
require_once 'db.inc.php';
require_once 'cms_http_functions.inc.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');

mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));

if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'Submit New Article':
if (isset($_POST['title'])
and isset($_POST['article_text'])
and isset($_SESSION['user_id']))
{
$sql = "INSERT INTO cms_articles " .
"(title,article_text, user_id, submit_date) " .
"VALUES ('" . $_POST['title'] .
"','" . $_POST['article_text'] .
"'," . $_SESSION['user_id'] . ",'" .
date("Y-m-d H:i:s", time()) . "')";

mysql_query($sql, $db)
or die('Could not submit article; ' . mysql_error());
}
redirect('cms_index.php');
break;

case 'Edit':
redirect('cms_compose.php?a=edit&article=' . $_POST['article']);
break;

case 'Save Changes':
if (isset($_POST['title'])
and isset($_POST['article_text'])
and isset($_POST['article_id']))
{
$sql = "UPDATE cms_articles " .
"SET title='" . $_POST['title'] .
"', article_text='" . $_POST['article_text'] . "', submit_date='" .
date("Y-m-d H:i:s", time()) . "' " .
"WHERE article_id=" . $_POST['article_id'];
if (isset($_POST['user_id'])) {
$sql .= " AND user_id=" . $_POST['user_id'];
}

mysql_query($sql, $conn)
or die('Could not update article; ' . mysql_error());
}

if (isset($_POST['user_id'])) {
redirect('cms_cpanel.php');
} else {
redirect('cms_pending.php');
}
break;

case 'Publish':
if ($_POST['article_id']) {
$sql = "UPDATE cms_articles " .
"SET is_published=1, publish_date='" .
date("Y-m-d H:i:s",time()) . "' " .
"WHERE article_id=" . $_POST['article_id'];
mysql_query($sql, $db)
or die('Could not publish article; ' . mysql_error());
}
redirect('cms_pending.php');
break;

case 'Retract':
if ($_POST['article_id']) {
$sql = "UPDATE cms_articles " .
"SET is_published=0, publish_date='' " .
"WHERE article_id=" . $_POST['article_id'];
mysql_query($sql, $conn)
or die('Could not retract article; ' . mysql_error());
}
redirect('cms_pending.php');
break;

case 'Delete':
if ($_POST['article_id']) {
$sql = "DELETE FROM cms_articles " .
"WHERE is_published=0 " .
"AND article_id=" . $_POST['article_id'];
mysql_query($sql, $conn)
or die('Could not delete article; ' . mysql_error());
}
redirect('cms_pending.php');
break;

case 'Submit Comment':
if (isset($_POST['article_id'])
and $_POST['article_id']
and isset($_POST['comment'])
and $_POST['comment'])
{
$sql = "INSERT INTO cms_comments " .
"(article_id,comment_date,user_id,comment_text ) " .
"VALUES (" . $_POST['article_id'] . ",'" .
date("Y-m-d H:i:s", time()) .
"'," . $_SESSION['user_id'] .
",'" . $_POST['comment_text'] . "')";
mysql_query($sql, $conn)
or die('Could add comment; ' . mysql_error());
}
redirect('cms_view_article.php?article=' . $_POST['article_id']);
break;

case 'remove':
if (isset($_GET['article_id'])
and isset($_SESSION['user_id']))
{
$sql = "DELETE FROM cms_articles " .
"WHERE article_id=" . $_GET['article_id'] .
" AND user_id=" . $_SESSION['user_id'];
mysql_query($sql, $conn)
or die('Could not remove article; ' . mysql_error());
}
redirect('cms_cpanel.php');
break;
}
} else {
redirect('cms_index.php');
}
?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors in Chapter 13 and 16 slauriault BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 November 29th, 2009 05:31 PM
Search ch 13, ch 16 sporik BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 October 27th, 2009 04:44 PM
Help??!! Error when working in Ch. 13 convert21 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 October 9th, 2009 03:39 AM
solved - P5AMWD, Ch 2, p83, Ex. 1 - array help BarrettB Beginning PHP 0 August 13th, 2007 02:52 PM
CHR(13) errors in CDO.CreateMHTMLBody() janaka44 Classic ASP Professional 0 April 5th, 2006 11:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.