Building a Relational Content Management System in PHP/MySQL - The Common Functions (
Page 3 of 5 )
These are a group of functions that are used by the script. We use common.php to store all of the functions that we call throughout the script.
<?
session_start();
include("config.php");
$dbh=mysql_connect ($dbhost, $dbuser, $dbpassword) or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ($dbname,$dbh);
define("DBH",$dbh);
function getPage($field='seoname',$value=''){
$result = mysql_query("SELECT * FROM articles WHERE
{$field}='{$value}'", DBH);
$page = mysql_fetch_assoc($result);
return $page;
}
function getPages($field='parent',$value='0'){
$result = mysql_query("SELECT * FROM articles WHERE
{$field}='{$value}'", DBH);
$pages = array();
while( $row = mysql_fetch_assoc($result) ){
$pages[$row['id']] = $row;
}
return $pages;
}
function AddPage(){
$_POST['akey'] = makeKey(10);
unset($_POST['id']);
$_POST['seoname'] = seoname($_POST['title']);
$query = "INSERT INTO articles (".implode(", ",array_keys
($_POST)).") VALUES ('".implode("', '",array_map
("mysql_real_escape_string",$_POST))."')";
mysql_query($query,DBH) or die( mysql_error() );
return mysql_insert_id();
}
function UpdatePage($pid){
$_POST['seoname'] = seoname($_POST['title']);
$query = "UPDATE articles SET ";
foreach($_POST as $field => $value) {
$query .= "$field = '".mysql_real_escape_string
($value)."', ";
}
$query = substr($query, 0, strlen($query)-2)." WHERE id =
'{$pid}'";
mysql_query($query,DBH) or die( mysql_error() );
return mysql_affected_rows();
}
function DeletePage($pid){
unset($_POST['step']);
$query = "DELETE FROM articles WHERE id = '{$pid}'";
mysql_query($query,DBH) or die( mysql_error() );
return mysql_affected_rows();
}
function seoname($string){
$string = ltrim($string);
$string = preg_replace( "/ +/", " ", strtolower($string) );
$string = str_replace(' - ', '-', $string);
$string = str_replace(array('-
','%',';','/','?',':','@','&','=','+','$',',','#','(',')'), '',
$string);
$search = array(' ', 'ä', 'ö',
'ü','ë','ï','é','è','à','ç',);
$replace = array
('','ae','oe','ue','e','i','e','e','a','c');
$string = str_replace($search, $replace, $string);
$string = preg_replace("/[^a-z0-9_-]/", "", $string);
$string = strtolower($string);
return urlencode($string);
}
?>
| | Discuss Building a Relational Content Management System in PHP/MySQL | | | | | | | This is a test comment. | | | | | | Hi, first of all thank you for this tutorial. I've just tried your codes but i think... | | | | | | Change:
function buildDropDown($parent,level = 1,$articleId){
To:
function... | | | | | | One more error:
$seoname = isset($_REQUEST['$seoname']) ? $_REQUEST['$seoname'] :... | | | | | | I forgot to mention, it's in index.php | | | | | | When i tried to enter an article, the following error occurred:
Fatal error: Call... | | | | | | Remove this line:
$_POST['akey'] = makeKey(10);
akey no longer gets used in... | | | | | | After i had made the last change, it worked.
Thank you. | | | | | | Thanks for Tutorial. I'm getting an error message saying
Fatal error: Call to... | | | | | | Hi there!
It was a nice tutorial and my hopes were high, but I was disappointed. I... | | | | | | It is possible that sessions in PHP in your case not work. | | | | | | i had the same "server encountered an internal error..."
the problem was a... | | | | | | Originally, I didn't have a line break in the .htaccess for this article.
Must have... | | | | | | Ive read all the above comments and made the necessary changes, but I still have... | | | | | | The header function is touchy. It must be called before anything is sent to the... | | | | | | Hi. I enjoyed your project. Everything works except getting the article itself to... | | | | | | Solution: Turn on (uncomment) mod_rewrite in the httpd.conf file.
Works great. | | | | | | Thank you very much for this tutorial. It works great for me with one exception: ... | | | | | | That's a nice tutorial. thank you. but what about deleting an article | | | | | | Anyone Knows how to use FCKeditor? I tried to do so but I can't. I am new to... | | | | | | I got your tutorial to work after reading all the comments and making that one last... | | | | | | I have just gone thru the tutorial and comments and have some aspects working but,... | | | | | | I am using your Relational CMS Tutorial as the basis of a content management system... | | | | | | I have a different database abstraction layer getting my MySQL commands to be... | | | | | | Hello everybody... someone have the code with the changes?
.. am still have the... | | | | | | Getting a "404" error. Not sure what the problem is, I'm using ubuntu with Apache2;... | | | | | | >>> Post your comment now! | | | | | |
|
 |