View Single Post
 
Old November 13th, 2010, 07:56 AM
jackzengfanwei jackzengfanwei is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default I use DMatt's code but it doesn't work ,finaly iI fount the error

The "cms_compose.php" If we do like this :
Code:
require 'db.inc.php';
 include 'cms_header.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));
 $action = (isset($_GET['action'])) ? $_GET['action'] : '';
 $article_id = (isset($_GET['article_id']) && ctype_digit($_GET['article_id'])) ? $_GET['article_id'] : '';

 $title = (isset($_POST['title'])) ? $_POST['title'] : '';
 $article_text = (isset($_POST['article_text'])) ? $_POST['article_text'] : '';
 //$user_id = (isset($_POST['user_id'])) ? $_POST['user_id'] : '';//delete this row
and edit the "cms_transact_article.php" Add "session_start()"
Code:
 require_once 'db.inc.php';
   require_once 'cms_http_functions.inc.php';
   session_start();//add this row   
  $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':
  		     $title = (isset($_POST['title'])) ? $_POST['title'] : '';
             $article_text = (isset($_POST['article_text'])) ? $_POST['article_text']: '';
        if (isset($_SESSION['user_id']) && !empty($title) &&
            !empty($article_text)) {
            $sql = 'INSERT INTO cms_articles
                    (user_id, submit_date, title, article_text)
                VALUES
                    (' . $_SESSION['user_id'] . ',
                    "' . date('Y-m-d H:i:s') . '",
                    "' . mysql_real_escape_string($title, $db) . '",
                    "' . mysql_real_escape_string($article_text, $db) . '")';
            mysql_query($sql, $db) or die(mysql_error($db));
        }
        redirect('cms_index.php');
        break;
and we can find it work . I 'm from china so my English is terrible ,forgive me!
The $_SESSION['user_id'] is always exist.and it's value only be changed in "cms_compose.php" "";

Last edited by jackzengfanwei; November 13th, 2010 at 08:03 AM..