Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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');
}
?>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.