4images Forum & Community

General / Allgemeines => Programming => Topic started by: Sunny C. on June 30, 2010, 07:15:36 PM

Title: Warning: sprintf() [function.sprintf]: Too few arguments + More Error
Post by: Sunny C. on June 30, 2010, 07:15:36 PM
I have few errors on my Site:
Quote
Warning: sprintf() [function.sprintf]: Too few arguments in /www/htdocs/w00b2576/gn/index.php on line 111
Quote
Bad SQL Query: SELECT news_title, news_image, news_text, user_name, news_date
FROM 4images_news
ORDER BY news_date
DESC LIMIT '0',
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

und
Quote
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/htdocs/w00b2576/gn/includes/db_mysql.php on line 116
Ich kann damit nichts anfangen, hat jemand eine Idee?

This is the Code:
//-----------------------------------------------------
// ----- Show news ------------------------------------
//-----------------------------------------------------

if (!isset($config['news_home_display']) || $config['news_home_display'] == 1)
$sql = "SELECT news_title, news_image, news_text, user_name, news_date
    FROM ".NEWS_TABLE."
ORDER BY news_date
DESC LIMIT 0, ".((isset($config['news_nb']))?$config['news_nb']:5);
else if ($config['news_home_display'] == 2)
$sql = "SELECT news_title, news_text, news_image, user_name, news_date
   FROM ".NEWS_TABLE."
   WHERE news_date > ".(time() - ((isset($config['news_nb_days']))?$config['news_nb_days']:15)*86400)."
   ORDER BY news_date DESC";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $news = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $news .= $lang['no_news'];
  $news .= "</td></tr></table>";
}
else  {
$news .= "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
$news .= "<img src=\"".$site_sess->url(TEMPLATE_PATH."/images".$config['news_image_verzeichnis']."".$image_row['news_image']."")."\" width=\"200\" height=\"266\">\n";
$news .= "</td></tr></table>\n";
$news .= "<div class=\"post type-post hentry category-allgemeines tag-kushina-uzumaki tag-kyuubi tag-manga-color tag-naruto tag-naruto-manga-497\">";

  while ($image_row = $site_db->fetch_array($result))
  {
$new_is_new .= ($image_row['news_date'] > time() - ((isset($config['news_cutoff']))?$config['news_cutoff']:3)*86400);
$news .= "<h2><a class=\"title\" href=\"#\">".$image_row['news_title']."</a></h2>\n";
$news .= "<div class=\"info\">\n";
$news .= "<span class=\"date\">\n";
$news .= "".(($new_is_new)?"<sup>".$lang['new']."</sup>":"").sprintf($lang['news_posted_by'], $image_row['user_name']);
$news .= "</span>\n";
$news .= "<span class=\"comments\">\n";
$news .= "".(($new_is_new)?"":"").sprintf(format_date($config['date_format']." ".$config['time_format'], $image_row['news_date']));
$news .= "".$lang['news_uhr']."";
$news .= "</span>\n";
$news .= "<div class=\"fixed\"></div>\n";
$news .= "</div\n";
$news .= "<div class=\"content\">\n";
$news .= "<div class='snap_preview'>\n";
$news .= "<p>";
$news .= format_text($image_row['news_text'], ((isset($config['news_html']))?$config['news_html']:0), 0, ((isset($config['news_bbcode']))?$config['news_bbcode']:1), ((isset($config['news_bbcodeimg']))?$config['news_bbcodeimg']:1));
$news .= "</p>\n";
$news .= "</tr>\n";
$news .= "</div>\n";
$news .= "<div class=\"fixed\"></div>\n";
$news .= "</div>\n";
$news .= "<div class=\"under\">\n";
$news .= "<span></span>\n";
$news .= "<span></span>\n";
$news .= "</div>\n";

  } // end while

  $news .= "</div>\n";
} // end else

$site_template->register_vars(array(
"news" => $news,
"news_main" => $lang['news_main']
));
unset($news);

Full index.php
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: index.php                                            *
 *        Copyright: (C) 2002-2009 Jan Sorgalla                           *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.7                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/

$templates_used = 'home,category_bit,whos_online,thumbnail_bit';
$main_template = 'home';

define('GET_CACHES', 1);
define('ROOT_PATH', './');
define('GET_USER_ONLINE', 1);
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();

if (isset($HTTP_GET_VARS['template']) || isset($HTTP_POST_VARS['template'])) {
  $template = (isset($HTTP_GET_VARS['template'])) ? get_basefile(stripslashes($HTTP_GET_VARS['template'])) : get_basefile(stripslashes($HTTP_POST_VARS['template']));
  if (!file_exists(TEMPLATE_PATH."/".$template.".".$site_template->template_extension)) {
    $template = "";
  }
  else {
    $main_template = $template;
  }
}
else {
  $template = "";
}
include(ROOT_PATH.'includes/page_header.php');

if (!empty($template)) {
  $clickstream = "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a>".$config['category_separator'].str_replace("_", " ", ucfirst($template));
  $site_template->register_vars("clickstream", $clickstream);
  $site_template->print_template($site_template->parse_template($main_template));
  include(ROOT_PATH.'includes/page_footer.php');
}

$cache_id = create_cache_id(
  'page.index',
  array(
    $user_info[$user_table_fields['user_id']],
    isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0,
    $config['template_dir'],
    $config['language_dir']
  )
);

if (!$cache_page_index || !$content = get_cache_file($cache_id)) {
// Always append session id if cache is enabled
if ($cache_page_index) {
  $old_session_mode = $site_sess->mode;
  $site_sess->mode = 'get';
}

ob_start();

//-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
$categories = get_categories(0);
if (!$categories)  {
  $categories = $lang['no_categories'];
}
$site_template->register_vars("categories", $categories);
unset($categories);

//-----------------------------------------------------
// ----- Show news ------------------------------------
//-----------------------------------------------------

if (!isset($config['news_home_display']) || $config['news_home_display'] == 1)
$sql = "SELECT news_title, news_image, news_text, user_name, news_date
        FROM ".NEWS_TABLE."
ORDER BY news_date
DESC LIMIT 0, ".((isset($config['news_nb']))?$config['news_nb']:5);
else if ($config['news_home_display'] == 2)
$sql = "SELECT news_title, news_text, news_image, user_name, news_date
       FROM ".NEWS_TABLE."
   WHERE news_date > ".(time() - ((isset($config['news_nb_days']))?$config['news_nb_days']:15)*86400)."
   ORDER BY news_date DESC";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $news = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $news .= $lang['no_news'];
  $news .= "</td></tr></table>";
}
else  {
    $news .= "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
$news .= "<img src=\"".$site_sess->url(TEMPLATE_PATH."/images".$config['news_image_verzeichnis']."".$image_row['news_image']."")."\" width=\"200\" height=\"266\">\n";
$news .= "</td></tr></table>\n";
    $news .= "<div class=\"post type-post hentry category-allgemeines tag-kushina-uzumaki tag-kyuubi tag-manga-color tag-naruto tag-naruto-manga-497\">";

  while ($image_row = $site_db->fetch_array($result))
  {
$new_is_new .= ($image_row['news_date'] > time() - ((isset($config['news_cutoff']))?$config['news_cutoff']:3)*86400);
$news .= "<h2><a class=\"title\" href=\"#\">".$image_row['news_title']."</a></h2>\n";
$news .= "<div class=\"info\">\n";
$news .= "<span class=\"date\">\n";
$news .= "".(($new_is_new)?"<sup>".$lang['new']."</sup>":"").sprintf($lang['news_posted_by'], $image_row['user_name']);
$news .= "</span>\n";
$news .= "<span class=\"comments\">\n";
$news .= "".(($new_is_new)?"":"").sprintf(format_date($config['date_format']." ".$config['time_format'], $image_row['news_date']));
$news .= "".$lang['news_uhr']."";
$news .= "</span>\n";
$news .= "<div class=\"fixed\"></div>\n";
    $news .= "</div\n";
    $news .= "<div class=\"content\">\n";
    $news .= "<div class='snap_preview'>\n";
$news .= "<p>";
$news .= format_text($image_row['news_text'], ((isset($config['news_html']))?$config['news_html']:0), 0, ((isset($config['news_bbcode']))?$config['news_bbcode']:1), ((isset($config['news_bbcodeimg']))?$config['news_bbcodeimg']:1));
$news .= "</p>\n";
    $news .= "</tr>\n";
$news .= "</div>\n";
$news .= "<div class=\"fixed\"></div>\n";
$news .= "</div>\n";
$news .= "<div class=\"under\">\n";
$news .= "<span></span>\n";
$news .= "<span></span>\n";
$news .= "</div>\n";

  } // end while

  $news .= "</div>\n";
} // end else

$site_template->register_vars(array(
"news" => $news,
"news_main" => $lang['news_main']
));
unset($news);

//-----------------------------------------------------
//--- Show New Images ---------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  "has_rss"   => true,
  "rss_title" => "RSS Feed: ".format_text($config['site_name'], 2)." (".str_replace(':', '', $lang['new_images']).")",
  "rss_url"   => $script_url."/rss.php?action=images"
));

$imgtable_width = ceil(intval($config['image_table_width']) / $config['image_cells']);
if ((substr($config['image_table_width'], -1)) == "%") {
  $imgtable_width .= "%";
}

$additional_sql = "";
if (!empty($additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", i.".$key;
  }
}

$num_new_images = $config['image_cells'];
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN").")
        ORDER BY i.image_date DESC
        LIMIT $num_new_images";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $new_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
  $new_images .= $lang['no_new_images'];
  $new_images .= "</td></tr></table>";
}
else  {
  $new_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  $count = 0;
  $bgcounter = 0;
  while ($image_row = $site_db->fetch_array($result)){
    if ($count == 0) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
      $new_images .= "<tr class=\"imagerow".$row_bg_number."\">\n";
    }
    $new_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

    show_image($image_row);
    $new_images .= $site_template->parse_template("thumbnail_bit");
    $new_images .= "\n</td>\n";
    $count++;
    if ($count == $config['image_cells']) {
      $new_images .= "</tr>\n";
      $count = 0;
    }
  } // end while

  if ($count > 0)  {
    $leftover = ($config['image_cells'] - $count);
    if ($leftover >= 1) {
      for ($f = 0; $f < $leftover; $f++) {
        $new_images .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n";
      }
      $new_images .= "</tr>\n";
    }
  }
  $new_images .= "</table>\n";
} // end else

$site_template->register_vars("new_images", $new_images);
unset($new_images);

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  "msg" => $msg,
  "clickstream" => $clickstream
));
$site_template->print_template($site_template->parse_template($main_template));

$content = ob_get_contents();
ob_end_clean();

if ($cache_page_index) {
  // Reset session mode
  $site_sess->mode = $old_session_mode;

  save_cache_file($cache_id, $content);
}

} // end if get_cache_file()

echo $content;

include(ROOT_PATH.'includes/page_footer.php');
?>
Title: Re: Warning: sprintf() [function.sprintf]: Too few arguments
Post by: V@no on June 30, 2010, 08:44:53 PM
What is the string you use in sprintf? and which line is it?
Title: Re: Warning: sprintf() [function.sprintf]: Too few arguments + More Error
Post by: Sunny C. on June 30, 2010, 08:57:30 PM
This is a modified Code from:
[MOD]Another Simple News Publishing Mod (http://www.4homepages.de/forum/index.php?topic=9064.0)
Title: Re: Warning: sprintf() [function.sprintf]: Too few arguments + More Error
Post by: Jan-Lukas on June 30, 2010, 08:58:19 PM
handelt es sich um den gleichen Mod ??

http://www.4homepages.de/forum/index.php?topic=9064.msg147998#msg147998
Title: Re: Warning: sprintf() [function.sprintf]: Too few arguments + More Error
Post by: Sunny C. on June 30, 2010, 09:15:11 PM
Yes, but here is the modified code!
Title: Re: Warning: sprintf() [function.sprintf]: Too few arguments + More Error
Post by: V@no on June 30, 2010, 09:50:39 PM
Yes, but here is the modified code!


Ok, I'll repeat again then

What is the string you use in sprintf? and which line is it?
Title: Re: Warning: sprintf() [function.sprintf]: Too few arguments + More Error
Post by: Sunny C. on June 30, 2010, 09:58:45 PM
$news .= "".(($new_is_new)?"<sup>".$lang['new']."</sup>":"").sprintf($lang['news_posted_by'], $image_row['user_name']);
Line in Full index.php = 119
Line in the first Code i post = 35
and
$news .= "".(($new_is_new)?"":"").sprintf(format_date($config['date_format']." ".$config['time_format'], $image_row['news_date']));
Line in Full index.php = 122
Line in the first Code i post = 38

and what is this?
Quote
Bad SQL Query: SELECT news_title, news_image, news_text, user_name, news_date
FROM 4images_news
ORDER BY news_date
DESC LIMIT '0',
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4