View Single Post
  #1 (permalink)  
Old December 4th, 2009, 01:31 PM
sporik sporik is offline
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