CMS Fatal Error

Issues related to the CMS tools of WYSIWYG Web Builder.
Forum rules
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901

MUST READ:
http://www.wysiwygwebbuilder.com/cms_tools.html
A lot of information about the Content Manager System can be found in the help/manual. Please read this first before posting any questions! Also check out the demo template that is include with the software.

CMS trouble shooting / FAQ:
viewtopic.php?f=10&t=43245
Post Reply
avent
 
 
Posts: 35
Joined: Wed Jan 02, 2013 9:28 pm

CMS Fatal Error

Post by avent »

When trying a project created from the demo, accessing the 'administration' page, after entering the password 'password', I get the following error:

"Fatal error: Uncaught mysqli_sql_exception: Duplicate column name 'title' in P:\svilweb\siti\beta\sito\cmsadmin.php:385 Stack trace: #0 P:\svilweb\siti\beta\sito\cmsadmin.php(385): mysqli_query(Object(mysqli), 'ALTER TABLE `CM...') #1 {main} thrown in P:\svilweb\siti\beta\sito\cmsadmin.php on line 385"
-
Anyway, the tables in the database appear to have been created automatically.
-
Any ideas?
User avatar
Pablo
 
Posts: 24174
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: CMS Fatal Error

Post by Pablo »

Can you please be more specific?
What is your exact configuration?
What is the generated code?
Where do you get this error message?
avent
 
 
Posts: 35
Joined: Wed Jan 02, 2013 9:28 pm

Re: CMS Fatal Error

Post by avent »

1) new project
new website from template -> online examples - Content Management System

2) create new database in local xampp

3) set database parameters in 'cms admin' e in 'cms view'

4) enabled error reporting in 'cms admin'

5) publish project in local server

6) open generated website

7) open administration form

8) type password 'password'

9) error appears inside the 'cms admin' form

10) in database all tables appear to be built



---- with this work around at line 385 the site seems to work

// Array di colonne da aggiungere se non esistono
$columns = array(
"title" => "VARCHAR(100)",
"description" => "VARCHAR(255)",
"keywords" => "VARCHAR(255)",
"seo_friendly_url" => "VARCHAR(100)",
"parent_id" => "INT DEFAULT NULL",
"search_index" => "TINYINT(1) NOT NULL DEFAULT 1"
);

foreach ($columns as $colName => $colType)
{
// Verifica se la colonna esiste già
$check_sql = "SHOW COLUMNS FROM `CMS_PAGES` LIKE '$colName'";
$check_result = mysqli_query($db, $check_sql);

if (mysqli_num_rows($check_result) == 0) {
// La colonna non esiste, la aggiungiamo
$sql = "ALTER TABLE `CMS_PAGES` ADD COLUMN `$colName` $colType";
if (!mysqli_query($db, $sql))
{
// Se l'errore non è "duplicate column", lo segnaliamo
if (mysqli_errno($db) != 1060)
{
die('Schema upgrade failed on ' . $colName . ': ' . mysqli_error($db));
}
}
}
}



---- original generated code

<?php

session_start();

error_reporting(E_ALL);

mb_internal_encoding('UTF-8');

mb_http_output('UTF-8');

mb_language('uni');

mb_regex_encoding('UTF-8');

ob_start('mb_output_handler');

define('ADMIN_PASS_HASH', '5f4dcc3b5aa765d61d8327deb882cf99');

define('MAIN_SCRIPT', basename(__FILE__));

$session_timeout = 600;

$mysql_server = 'localhost';

$mysql_username = 'root';

$mysql_password = '';

$mysql_database = 'sql1899866_3';

$username = 'admin';

$labelHome = 'Home';

$labelName = 'Name';

$labelCreatedBy = 'Created by';

$labelLastUpdate = 'Last update';

$labelVisible = 'Visible';

$labelSearchIndex = 'Search Index';

$labelHomePage = 'Home page';

$labelViews = 'Views';

$labelOrder = 'Order';

$labelContent = 'Content';

$labelURL = 'External URL';

$labelExtraData = 'Extra data';

$labelParent = 'Parent Page';

$labelTitle = 'Title';

$labelDescription = 'Description';

$labelKeywords = 'Keywords';

$labelAction = 'Action';

$labelNewPage = 'New Page';

$labelCaption = 'Content Management System';

$labelLogin = 'Login';

$labelLogout = 'Logout';

$labelEdit = 'Edit';

$labelCopy = 'Copy';

$labelDelete = 'Delete';

$labelYes = 'Yes';

$labelNo = 'No';

$labelSave = 'Save';

$labelCancel = 'Cancel';

$labelUp = 'Up';

$labelDown = 'Down';

$labelOwner = 'Owner';

$labelPlugins = 'Plugins';

$labelUserName = 'Username';

$labelPassword = 'Password';

$admin_password = isset($_COOKIE['cmsadmin_pwd']) ? $_COOKIE['cmsadmin_pwd'] : '';



if (empty($admin_password))

{

if (isset($_POST['admin_password']))

{

$admin_password = md5($_POST['admin_password']);

if ($admin_password == ADMIN_PASS_HASH)

{

setcookie('cmsadmin_pwd', $admin_password, time() + $session_timeout);

}

}

}

else

if ($admin_password == ADMIN_PASS_HASH)

{

setcookie('cmsadmin_pwd', $admin_password, time() + $session_timeout);

}

$authorized = ($admin_password == ADMIN_PASS_HASH);

if (!$authorized)

{

if (isset($_SESSION['cms_user']))

{

$authorized = true;

$username = $_SESSION['cms_user'];

}

}

$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

$name = isset($_POST['name']) ? $_POST['name'] : '';

$content = isset($_POST['content']) ? $_POST['content'] : '';

$url = isset($_POST['url']) ? $_POST['url'] : '';

$extra_data = isset($_POST['extra_data']) ? $_POST['extra_data'] : '';

$title = isset($_POST['title']) ? $_POST['title'] : '';

$description = isset($_POST['description']) ? $_POST['description'] : '';

$keywords = isset($_POST['keywords']) ? $_POST['keywords'] : '';

$created_by = isset($_POST['created_by']) ? $_POST['created_by'] : '';

$visible = isset($_POST['visible']) ? $_POST['visible'] : 0;

$search_index = isset($_POST['search_index']) ? $_POST['search_index'] : 1;

$timestamp = date("y-m-d H:i:s", time());

$parent_id = isset($_REQUEST['parent_id']) ? $_REQUEST['parent_id'] : "-1";

if ($parent_id == -1)

$parent_id = "NULL";

$plugins = array();

if (file_exists('./plugins/'))

{

$handle = opendir('./plugins/');

while ($item = readdir($handle))

{

if ($item != "." && $item != ".." && is_dir('./plugins/'.$item) && substr($item, 0, 1) != '_')

{

require_once('./plugins/'.$item.'/plugin.php');

$plugins[$item] = $plugin;

}

}

closedir($handle);

}

$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password);

if (!$db)

{

die('Failed to connect to database server!<br>'.mysqli_error($db));

}

mysqli_select_db($db, $mysql_database) or die('Failed to select database<br>'.mysqli_error($db));

mysqli_query($db, 'SET NAMES "UTF8"');

mysqli_query($db, "SET collation_connection='utf8_general_ci'");

mysqli_query($db, "SET collation_server='utf8_general_ci'");

mysqli_query($db, "SET character_set_client='utf8'");

mysqli_query($db, "SET character_set_connection='utf8'");

mysqli_query($db, "SET character_set_results='utf8'");

mysqli_query($db, "SET character_set_server='utf8'");

mysqli_set_charset($db, 'utf8');

if ($action == 'login')

{

if (!$authorized && function_exists('usermanager_login'))

{

usermanager_login();

}

$action = '';

}

if ($authorized)

{

$content = mysqli_real_escape_string($db, $content);

$url = mysqli_real_escape_string($db, $url);

$name = mysqli_real_escape_string($db, $name);

$extra_data = mysqli_real_escape_string($db, $extra_data);

$title = mysqli_real_escape_string($db, $title);

$description = mysqli_real_escape_string($db, $description);

$keywords = mysqli_real_escape_string($db, $keywords);

$created_by = mysqli_real_escape_string($db, $created_by);

$sql = "CREATE TABLE IF NOT EXISTS CMS_PAGES (id INT UNSIGNED NOT NULL AUTO_INCREMENT,

category_id INT NOT NULL,

parent_id INT DEFAULT NULL,

name VARCHAR(255) NOT NULL,

content TEXT NOT NULL,

home TINYINT(1) NOT NULL,

visible TINYINT(1) NOT NULL,

create_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

created_by VARCHAR(255) NOT NULL,

last_update_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

last_update_by VARCHAR(255) NOT NULL,

views INT NOT NULL,

menu_index INT NOT NULL,

url VARCHAR(255),

extra_data VARCHAR(255),

title VARCHAR(100),

description VARCHAR(255),

keywords VARCHAR(255),

seo_friendly_url VARCHAR(100),

search_index TINYINT(1) NOT NULL,

PRIMARY KEY(id));";

$result = mysqli_query($db, $sql);

if (!$result)

{

die('Invalid query: ' . mysqli_error($db));

}

$sql = "CREATE TABLE IF NOT EXISTS CMS_SEARCH_WORDS (id INT UNSIGNED NOT NULL AUTO_INCREMENT,

word VARCHAR(50) NOT NULL,

PRIMARY KEY (id));";

$result = mysqli_query($db, $sql);

if (!$result)

{

die('Invalid query: ' . mysqli_error($db));

}

$sql = "CREATE TABLE IF NOT EXISTS CMS_SEARCH_WORDMATCH (page_id INT UNSIGNED NOT NULL,

word_id INT UNSIGNED NOT NULL,

PRIMARY KEY(page_id, word_id));";

$result = mysqli_query($db, $sql);

if (!$result)

{

die('Invalid query: ' . mysqli_error($db));

}

$columns = array(

"title VARCHAR(100)",

"description VARCHAR(255)",

"keywords VARCHAR(255)",

"seo_friendly_url VARCHAR(100)",

"parent_id INT DEFAULT NULL",

"search_index TINYINT(1) NOT NULL DEFAULT 1"

);

foreach ($columns as $colDef)

{

$sql = "ALTER TABLE `CMS_PAGES` ADD COLUMN $colDef";

if (!mysqli_query($db, $sql))

{

if (mysqli_errno($db) != 1060)

{

die('Schema upgrade failed on ' . $colDef . ': ' . mysqli_error($db));

}

}

}

foreach($plugins as $pluginname=>$p)

{

if (isset($p['admin']['init']))

{

$fn_init = $p['admin']['init']['function'];

$fn_init();

}

}

if (!empty($action))

{

if ($action == 'delete')

{

$menu_index = 0;

$sql = "SELECT * FROM CMS_PAGES WHERE `id` = '$id'";

$result = mysqli_query($db, $sql);

if ($data = mysqli_fetch_array($result))

{

$menu_index = $data['menu_index'];

}

$sql = "DELETE FROM CMS_PAGES WHERE `id` = '$id'";

mysqli_query($db, $sql);

$sql = "DELETE FROM CMS_SEARCH_WORDMATCH WHERE `page_id` = '$id'";

mysqli_query($db, $sql);

$sql = "UPDATE CMS_PAGES SET menu_index=menu_index-1 WHERE menu_index > '$menu_index'";

mysqli_query($db, $sql);

mysqli_close($db);

header('Location: '.basename(__FILE__));

exit;

}

else

if ($action == 'update')

{

$seo_friendly_url = strtolower($title);

$seo_friendly_url = preg_replace("/[^a-z0-9_\s-]/", "", $seo_friendly_url);

$seo_friendly_url = preg_replace("/[\s-]+/", " ", $seo_friendly_url);

$seo_friendly_url = preg_replace("/[\s_]/", "-", $seo_friendly_url);

$sql = "UPDATE CMS_PAGES SET `name` = '$name', `content` = '$content', `url` = '$url', `extra_data` = '$extra_data', `title` = '$title', `description` = '$description', `keywords` = '$keywords', `seo_friendly_url` = '$seo_friendly_url', `visible` = $visible, `parent_id` = $parent_id, `search_index` = $search_index, `last_update_date` = '$timestamp', ";

if ($username == 'admin' && $created_by != '')

{

$sql .= "`created_by` = '$created_by', ";

}

$sql .= "`last_update_by` = '$username' WHERE `id` = '$id'";

mysqli_query($db, $sql);

addToSearchIndex($db, $id, $content, $search_index);

foreach($plugins as $pluginname=>$p)

{

if (isset($p['admin']['update']))

{

$fn_update = $p['admin']['update']['function'];

$fn_update($id);

}

}

mysqli_close($db);

header('Location: '.basename(__FILE__));

exit;

}

else

if ($action == 'create')

{

if ($username != 'admin' || $created_by == '')

{

$created_by = $username;

}

$sql = "SELECT * FROM CMS_PAGES";

$result = mysqli_query($db, $sql);

$menu_index = mysqli_num_rows($result);

$menu_index = $menu_index + 1;

$seo_friendly_url = strtolower($title);

$seo_friendly_url = preg_replace("/[^a-z0-9_\s-]/", "", $seo_friendly_url);

$seo_friendly_url = preg_replace("/[\s-]+/", " ", $seo_friendly_url);

$seo_friendly_url = preg_replace("/[\s_]/", "-", $seo_friendly_url);

$sql = "INSERT CMS_PAGES (`category_id`,`name`,`content`,`url`,`extra_data`,`title`,`description`,`keywords`,`visible`,`parent_id`,`home`,`create_date`,`created_by`,`last_update_date`,`last_update_by`,`menu_index`,`views`,`seo_friendly_url`, `search_index`) VALUES (0,'$name','$content','$url','$extra_data','$title','$description','$keywords','$visible',$parent_id,0,'$timestamp','$created_by','$timestamp','$username','$menu_index',0,'$seo_friendly_url','$search_index')";

mysqli_query($db, $sql);

$id = mysqli_insert_id($db);

addToSearchIndex($db, $id, $content, $search_index);

foreach($plugins as $pluginname=>$p)

{

if (isset($p['admin']['update']))

{

$fn_update = $p['admin']['update']['function'];

$fn_update($id);

}

}

mysqli_close($db);

header('Location: '.basename(__FILE__));

exit;

}

else

if ($action == 'home')

{

$sql = "UPDATE CMS_PAGES SET `home` = 0";

mysqli_query($db, $sql);

$sql = "UPDATE CMS_PAGES SET `home` = 1 WHERE `id` = '$id'";

mysqli_query($db, $sql);

mysqli_close($db);

header('Location: '.basename(__FILE__));

exit;

}

else

if ($action == 'moveup' || $action == 'movedown')

{

$menu_index = 0;

$sql = "SELECT * FROM CMS_PAGES WHERE `id` = '$id'";

$result = mysqli_query($db, $sql);

if ($data = mysqli_fetch_array($result))

{

$menu_index = $data['menu_index'];

}

if ($action == 'moveup')

$new_index = $menu_index - 1;

else

$new_index = $menu_index + 1;

$sql = "UPDATE CMS_PAGES SET menu_index = $menu_index WHERE menu_index = '$new_index'";

mysqli_query($db, $sql);

$sql = "UPDATE CMS_PAGES SET menu_index = $new_index WHERE id = '$id'";

mysqli_query($db, $sql);

mysqli_close($db);

header('Location: '.basename(__FILE__));

exit;

}

else

if ($action == 'logout')

{

session_unset();

session_destroy();

setcookie('cmsadmin_pwd', '', time() - 3600);

header('Location: '.basename(__FILE__));

exit;

}

else

{

if (isset($_REQUEST['plugin']))

{

require('./plugins/'.$_REQUEST['plugin'].'/'.$action.'.php');

exit;

}

}

}

}

function addToSearchIndex($db, $page_id, $content, $search_index)

{

$sql = "DELETE CMS_SEARCH_WORDS FROM CMS_SEARCH_WORDS INNER JOIN CMS_SEARCH_WORDMATCH ON CMS_SEARCH_WORDMATCH.word_id = CMS_SEARCH_WORDS.id WHERE CMS_SEARCH_WORDMATCH.page_id = '$page_id'";

mysqli_query($db, $sql);

$sql = "DELETE FROM CMS_SEARCH_WORDMATCH WHERE page_id = '$page_id'";

mysqli_query($db, $sql);

if (!$search_index)

return;

$content = strtolower(html_entity_decode($content));

static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');

static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');

$content = str_replace('<br>', ' ', $content);

$content = stripslashes($content);

$content = strip_tags(strtolower($content));

$content = preg_replace('/[\n\r]/is', ' ', $content);

for($i = 0; $i < count($drop_char_match); $i++)

{

$content = str_replace($drop_char_match[$i], $drop_char_replace[$i], $content);

}

$content = str_replace('*', ' ', $content);

$words = preg_split('/\s+/', trim($content));

$id_array = array();

$index = 0;

foreach ($words as $word)

{

if (strlen($word) < 2) continue;

if (is_numeric($word)) continue;

$sql = "SELECT id FROM CMS_SEARCH_WORDS WHERE word = '$word';";

$result = mysqli_query($db, $sql);

if (!$result)

{

die('Invalid query: ' . mysqli_error($db));

}

$record = mysqli_fetch_object($result);

if (!$record || !$word_id = $record->id)

{

$sql = "INSERT INTO CMS_SEARCH_WORDS (word) VALUES ('$word');";

mysqli_query($db, $sql);

$word_id = mysqli_insert_id($db);

}

$id_array[$index] = $word_id;

$index++;

}

foreach ($id_array as $word_id)

{

$sql = "INSERT INTO CMS_SEARCH_WORDMATCH (`word_id`, `page_id`) VALUES ('$word_id', '$page_id');";

mysqli_query($db, $sql);

}

}

?>

<!doctype html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Content Management System</title>

<link rel="stylesheet" href="cmsadmin.css" type="text/css">

<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>

<script type="text/javascript">

$(document).ready(function()

{

$('ul.tabs').each(function()

{

var $active, $content, $links = $(this).find('a');

if (window.location.hash == '')

{

$active = $($links[0]);

}

else

{

$active = $($links.filter('[href="'+window.location.hash+'"]')[0] || $links[0]);

}

$active.addClass('active');

$content = $($active.attr('href'));

$links.not($active).each(function ()

{

$($(this).attr('href')).hide();

});

$(this).on('click', 'a', function(e)

{

$active.removeClass('active');

$content.hide();

$active = $(this);

$content = $($(this).attr('href'));

$active.addClass('active');

$content.show();

e.preventDefault();

});

});

});

</script>

</head>

<body>

<?php



if (!$authorized)

{

echo "<table width=\"100%\" border=\"0\">\n";

echo "<tr><td colspan=\"2\" align=\"center\">$labelCaption<br>&nbsp;</td></tr>\n";

echo "<form method=\"post\" action=\"" .basename(__FILE__) . "\">\n";

echo "<tr><td width=\"50%\" align=\"right\"><label for=\"admin_username\">$labelUserName&nbsp;&nbsp;</label></td><td width=\"50%\"><input class=\"form-control\" type=\"text\" id=\"admin_username\" name=\"admin_username\" size=\"20\"></td></tr>\n";

echo "<tr><td align=\"right\"><label for=\"admin_password\">$labelPassword&nbsp;&nbsp;</label></td><td><input class=\"form-control\" type=\"password\" id=\"admin_password\" name=\"admin_password\" size=\"20\"></td></tr>\n";

echo "<tr><td>&nbsp;</td><td align=\"left\"><input class=\"btn\" type=\"submit\" value=\"$labelLogin\" name=\"submit\"></td></tr>\n";

echo "<input type=\"hidden\" name=\"action\" value=\"login\">\n";

echo "</form>\n";

echo "</tr></td></table>\n";

}

else

{

echo "<ul id=\"nav\">\n";

echo " <li><a href=\"" . basename(__FILE__) . "\">$labelHome</a></li>\n";

echo " <li><a href=\"" . basename(__FILE__) . "?action=new\">$labelNewPage</a></li>\n";

if (sizeof($plugins) > 0)

{

echo " <li><a ontouchstart=''>$labelPlugins</a>\n";

echo " <ul>\n";

foreach($plugins as $pluginname=>$p)

{

if (isset($p['admin']['menu']))

{

foreach ($p['admin']['menu'] as $text=>$page)

{

echo " <li><a href=\"cmsadmin_plugin.php?_plugin=".$pluginname."&amp;_page=".$page."\">".$text."</a></li>\n";

}

}

}

echo " </ul>\n";

echo " </li>\n";

}

echo " <li><a href=\"" . basename(__FILE__) . "?action=logout\">$labelLogout</a></li>\n";

echo "</ul>\n";

if (!empty($action))

{

if ($action == 'edit' || $action == 'new' || $action == 'copy')

{

$sql = "SELECT * FROM CMS_PAGES WHERE id = '".$id."'";

$result = mysqli_query($db, $sql);

$name_value = '';

$content_value = '';

$visible_value = '';

$url_value = '';

$extra_data_value = '';

$title_value = '';

$description_value = '';

$keywords_value = '';

$created_by_value = '';

$parent_value = -1;

$search_index_value = '';

if ($data = mysqli_fetch_array($result))

{

$name_value = htmlspecialchars($data['name']);

$content_value = $data['content'];

$visible_value = $data['visible'];

$url_value = htmlspecialchars($data['url']);

$extra_data_value = htmlspecialchars($data['extra_data']);

$title_value = htmlspecialchars($data['title']);

$description_value = htmlspecialchars($data['description']);

$keywords_value = htmlspecialchars($data['keywords']);

$created_by_value = htmlspecialchars($data['created_by']);

$parent_value = ($data['parent_id'] !== NULL) ? $data['parent_id'] : -1;

$search_index_value = $data['search_index'];

}

$extra_tabs = array();

foreach($plugins as $pluginname=>$p)

{

if (isset($p['admin']['tab']))

{

$extra_tabs[$p['admin']['tab']['name']] = $p['admin']['tab']['function'];

}

}

echo "<ul class=\"tabs\">\n";

echo "<li><a href=\"#tab-general\">General</a></li>\n";

foreach($extra_tabs as $name=>$fn)

{

echo "<li><a href=\"#tab-".preg_replace('/[^a-z0-9A-Z]/', '', $name)."\">".htmlspecialchars($name)."</a></li>\n";

}

echo "</ul>\n";

echo "<form action=\"" . basename(__FILE__) . "\" method=\"post\">\n";

echo "<div class=\"tab\" id=\"tab-general\">\n";

if ($action == 'new' || $action == 'copy')

{

echo "<input type=\"hidden\" name=\"action\" value=\"create\">\n";

}

else

{

echo "<input type=\"hidden\" name=\"action\" value=\"update\">\n";

}

echo "<input type=\"hidden\" name=\"id\" value=\"". $id . "\">\n";

echo "<table width=\"100%\" border=\"0\">\n";

echo "<tr><td style=\"width:10%;white-space:nowrap;\"><label for=\"name\">$labelName:</label></td>\n";

echo "<td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"name\" name=\"name\" value=\"" . $name_value . "\"></td></tr>\n";

echo "<tr><td><label for=\"editor\">$labelContent:</label></td>\n";

echo "<td><textarea id=\"editor\" style=\"width:100%;height:200px\" name=\"content\">" . $content_value . "</textarea></td></tr>\n";

echo "<tr><td><label for=\"url\">$labelURL:</label></td>\n";

echo "<td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"url\" name=\"url\" value=\"" . $url_value . "\"></td></tr>\n";

echo "<tr><td><label for=\"extra_data\">$labelExtraData:</label></td>\n";

echo "<td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"extra_data\" name=\"extra_data\" value=\"" . $extra_data_value . "\"></td></tr>\n";

echo "<tr><td><label for=\"title\">$labelTitle:</label></td>\n";

echo "<td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"title\" name=\"title\" value=\"" . $title_value . "\"></td></tr>\n";

echo "<tr><td><label for=\"description\">$labelDescription:</label></td>\n";

echo "<td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"description\" name=\"description\" value=\"" . $description_value . "\"></td></tr>\n";

echo "<tr><td><label for=\"keywords\">$labelKeywords:</label></td>\n";

echo "<td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"keywords\" name=\"keywords\" value=\"" . $keywords_value . "\"></td></tr>\n";

echo "<tr><td><label for=\"visible\">$labelVisible:</label></td>\n";

echo "<td><select class=\"form-control\" style=\"width:25%;\" id=\"visible\" name=\"visible\" size=\"1\"><option " . ($visible_value == "0" ? "selected " : "") . "value=\"0\">hidden</option><option " . ($visible_value != "0" ? "selected " : "") . "value=\"1\">visible</option></select></td></tr>\n";

echo "<tr><td><label for=\"search_index\">$labelSearchIndex:</label></td>\n";

echo "<td><select class=\"form-control\" style=\"width:25%;\" id=\"search_index\" name=\"search_index\" size=\"1\"><option " . ($search_index_value == "0" ? "selected " : "") . "value=\"0\">false</option><option " . ($search_index_value != "0" ? "selected " : "") . "value=\"1\">true</option></select></td></tr>\n";

if ($username == 'admin')

{

echo "<tr><td><label for=\"created_by\">$labelOwner:</label></td><td><input class=\"form-control\" type=\"text\" style=\"width:100%;\" id=\"created_by\" name=\"created_by\" value=\"" . $created_by_value . "\"></td></tr>\n";

}

echo "<tr><td><label for=\"parent_id\">$labelParent:</label></td>\n";

echo "<td><select class=\"form-control\" style=\"width:25%;\" id=\"parent_id\" name=\"parent_id\" size=\"1\">";

echo "<option " . ($parent_value == -1 ? "selected " : "") . "value=\"-1\">(None)</option>";

$sql = "SELECT * FROM CMS_PAGES";

if ($username != 'admin')

{

$sql = $sql . " WHERE created_by = '".$username."'";

}

$sql = $sql . " ORDER BY menu_index ASC";

$result = mysqli_query($db, $sql);

$num_rows = mysqli_num_rows($result);

while ($data = mysqli_fetch_array($result))

{

if ($data['id'] != $id)

{

echo "<option " . ($data['id'] == $parent_value ? "selected " : "") . "value=\"". $data['id'] ."\">". $data['name'] . "</option>";

}

}

echo "</select></td></tr>\n";

echo "</table>\n";

echo "</div>\n";

foreach($extra_tabs as $name=>$fn)

{

echo "<div class=\"tab\" id=\"tab-".preg_replace('/[^a-z0-9A-Z]/', '', $name)."\">\n";

echo $fn();

echo "</div>\n";

}

echo "<input class=\"btn\" style=\"margin-top:6px;\" type=\"submit\" name=\"save\" value=\"$labelSave\">\n";

echo "</form>\n";

}

}

else

{

echo "<table class=\"table table-striped table-hover\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n";

echo "<thead>\n";

echo "<tr><th>$labelName</th>\n";

echo "<th>$labelCreatedBy</th>\n";

echo "<th>$labelLastUpdate</th>\n";

echo "<th>$labelVisible</th>\n";

echo "<th>$labelHomePage</th>\n";

echo "<th>$labelViews</th>\n";

echo "<th>$labelOrder</th>\n";

echo "<th>$labelAction</th></tr>\n";

echo "</thead>\n";

echo "<tbody>\n";

$sql = "SELECT * FROM CMS_PAGES";

if ($username != 'admin')

{

$sql = $sql . " WHERE created_by = '".$username."'";

}

$sql = $sql . " ORDER BY menu_index ASC";

$result = mysqli_query($db, $sql);

$num_rows = mysqli_num_rows($result);

while ($data = mysqli_fetch_array($result))

{

echo "<tr>\n";

echo "<td>" . $data['name'] . "</td>\n";

echo "<td>" . $data['created_by'] . "</td>\n";

echo "<td>" . $data['last_update_date'] . "</td>\n";

echo "<td>" . ($data['visible'] == "0" ? $labelNo : $labelYes) . "</td>\n";

echo "<td>";

if ($data['home'] == "1")

echo $labelYes;

else

echo " <a href=\"" . basename(__FILE__) . "?action=home&id=" . $data['id'] . "\">$labelNo</a>";

echo "</td>\n";

echo "<td>" . $data['views'] . "</td>\n";

echo "<td>";

if ($data['menu_index'] <= 1)

{

echo " <a href=\"" . basename(__FILE__) . "?action=movedown&id=" . $data['id'] . "\">$labelDown</a>";

}

elseif ($data['menu_index'] >= $num_rows)

{

echo " <a href=\"" . basename(__FILE__) . "?action=moveup&id=" . $data['id'] . "\">$labelUp</a>";

}

else

{

echo " <a href=\"" . basename(__FILE__) . "?action=moveup&id=" . $data['id'] . "\">$labelUp</a> &nbsp; ";

echo " <a href=\"" . basename(__FILE__) . "?action=movedown&id=" . $data['id'] . "\">$labelDown</a>";

}

echo "</td>\n";

echo "<td>\n";

echo " <a href=\"" . basename(__FILE__) . "?action=edit&id=" . $data['id'] . "\">$labelEdit</a> | \n";

echo " <a href=\"" . basename(__FILE__) . "?action=copy&id=" . $data['id'] . "\">$labelCopy</a> | \n";

echo " <a href=\"" . basename(__FILE__) . "?action=delete&id=" . $data['id'] . "\">$labelDelete</a>\n";

echo "</td>\n";

echo "</tr>\n";

}

echo "</tbody>\n";

echo "</table>\n";

}

}



?>

</body>

</html>
User avatar
Pablo
 
Posts: 24174
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: CMS Fatal Error

Post by Pablo »

You should not change any code manually

I'm sorry, but it is still not clear for me where exactly did the error occur?
What did you change to make it work?
avent
 
 
Posts: 35
Joined: Wed Jan 02, 2013 9:28 pm

Re: CMS Fatal Error

Post by avent »

Sorry for my poor English.

These are the steps:
I created a new project from the online demo;
I used an empty database created on a local XAMPP server;
I configured the database data in the CMS components;
I published the project as is, without any changes, to the local server;
I tested the generated site and, after setting the default password ('password') in the administration form, the error immediately appeared right inside the form area;
I noted, however, that the tables were automatically created as expected;
Since the error was an attempt to create a column that already existed, I tried manually modifying the code by inserting a check to avoid adding existing columns. This way, the site worked.

If it's helpful, I could take screenshots of all the steps and send them along with the completed project.
Let me know.
avent
 
 
Posts: 35
Joined: Wed Jan 02, 2013 9:28 pm

Re: CMS Fatal Error

Post by avent »

This is my temporary workaround on file 'cmsadmin.php':

---- this is the fragment code in file generated by WWB vers. 20.4.1
...
...

$columns = array(
"title VARCHAR(100)",
"description VARCHAR(255)",
"keywords VARCHAR(255)",
"seo_friendly_url VARCHAR(100)",
"parent_id INT DEFAULT NULL",
"search_index TINYINT(1) NOT NULL DEFAULT 1"
);

foreach ($columns as $colDef)
{
$sql = "ALTER TABLE `CMS_PAGES` ADD COLUMN $colDef";
if (!mysqli_query($db, $sql)) <======= this is the line 385 that give the error
{
if (mysqli_errno($db) != 1060)
{
die('Schema upgrade failed on ' . $colDef . ': ' . mysqli_error($db));
}
}
}
...
...

-----------------------------------------------
---- this is the new code (workaround) in place of the one above

...
...
// Array di colonne da aggiungere se non esistono
$columns = array(
"title" => "VARCHAR(100)",
"description" => "VARCHAR(255)",
"keywords" => "VARCHAR(255)",
"seo_friendly_url" => "VARCHAR(100)",
"parent_id" => "INT DEFAULT NULL",
"search_index" => "TINYINT(1) NOT NULL DEFAULT 1"
);

foreach ($columns as $colName => $colType)
{
// Verifica se la colonna esiste già
$check_sql = "SHOW COLUMNS FROM `CMS_PAGES` LIKE '$colName'";
$check_result = mysqli_query($db, $check_sql);

if (mysqli_num_rows($check_result) == 0) {
// La colonna non esiste, la aggiungiamo
$sql = "ALTER TABLE `CMS_PAGES` ADD COLUMN `$colName` $colType";
if (!mysqli_query($db, $sql))
{
// Se l'errore non è "duplicate column", lo segnaliamo

if (mysqli_errno($db) != 1060)
{
die('Schema upgrade failed on ' . $colName . ': ' . mysqli_error($db));
}
}
}
}
...
...

--------------------
User avatar
Pablo
 
Posts: 24174
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: CMS Fatal Error

Post by Pablo »

Do you mean that you have added quotes to the SQL to make it work?
avent
 
 
Posts: 35
Joined: Wed Jan 02, 2013 9:28 pm

Re: CMS Fatal Error

Post by avent »

The problem was trying to add an existing column.
To resolve the issue, the SQL script was replaced with an array so that the columns could be added individually with a loop rather than a single script.
Before adding the column, it checks to see if it already exists; if so, it isn't added.
Of course, this is just a temporary workaround, but it seems to work; it's certainly not the optimal solution because there could be a problem with the script's logic.
I simply assume the script is trying to recreate an existing table.
User avatar
Pablo
 
Posts: 24174
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: CMS Fatal Error

Post by Pablo »

There has never been an issue with this script so it's not clear for me why you need to changed this.
The script should continue to run even if the table already exists.
avent
 
 
Posts: 35
Joined: Wed Jan 02, 2013 9:28 pm

Re: CMS Fatal Error

Post by avent »

I have no idea!
I used a simple local XAMPP server with no modifications, an empty database, and a WWB project created from the CMS demo without any modifications.
Anyway, don't worry; if this is a problem that's unique to me, don't waste your time; I was just testing it to decide whether to use it for a future project.
You can consider this ticket closed.
Post Reply