Thank you for viewing my problem.
I am new to php and am attempting to write a small content management system. I am using a data file to store information but am having an issue when attempting to retrieve the data.
I am able to write the data to the file. I am retrieving data from the file to create a link page designed to call the main data into a template page when the link is clicked.
When retrieved, all of the data will render in the right place, however, the script is calling in the wrong string.
Additionally, the script writing the data will at random create a phantom string that does not show up on the data file but does show up on the data list on the admin panel.
The link to the created link page is:
http://seo-niche-site-manager.com/test/articles.php
I have 4 test articles listed but you will notice when placing your mouse over the link that instead of listing the articleid's in sequence of 0,1,2,3 the script has assigned articleid's of 0,2,4,5
For the test run this is the data file that has been created:
General Niche Topics This is a Test Article for this Script 3 sub title 3 brief description 3 prime 3 content 3 Author 3
<br>Staff Writer<br>
General Niche Topics This is a Test Article for this Script 2 sub title 2 brief description 2 prime 2 content 2 Author 2
<br>Staff Writer<br>
Another Catagory This is a Test Article for this Script 1 sub title 1 brief description 1 prime 1 content 1 Author1<br>Staff Writer<br>
Another Catagory This is a Test Article for this Script 0 sub title 0 brief description 0 prime 0 content 0 Author<br>Staff Writer<br>
The Code the admin is using to wrtie to the data file is:
<?php
if ($action == 'add')
{
$artcat = $_POST['artcat'];
$arttitle = $_POST['arttitle'];
$artsub = $_POST['artsub'];
$artdesc = $_POST['artdesc'];
$artkeys = $_POST['artkeys'];
$artprimekeys = $_POST['artprimekeys'];
$artbody = $_POST['artbody'];
$artauth = $_POST['artauth'];
$fp = fopen("../articles/article.dat","rb");
$articles = @fread($fp,filesize("../articles/article.dat"));
fclose($fp);
$replacement = "$artcat\t$arttitle\t$artsub\t$artdesc\t$artkeys\t$artprimekeys\t$artbody\t$artauth\n";
$replacement .= $articles;
$fp = fopen("../articles/article.dat","wb");
fputs($fp,$replacement);
fclose($fp);
echo "<Script language=\"javascript\">window.location=\"articles.php\"</script>";
}
?>
The code used on the link listing page is:
<?php
$catagory=array();
$catagory = file('catagories/catagories.dat');
if (count($catagory)==0)
{
echo '<div class="noArt"><b><small>There Are No Catagories Listed as of Yet</small></b></div>';
}
else
{
$i = 0;
foreach ($catagory as $thiscatagory)
{
$thiscatagory = trim($thiscatagory);
if(!empty($thiscatagory))
{
list($catagory) = explode("\t",$thiscatagory);
echo '<div id="catHead">'.$catagory.'</div>';
$articles = array();
$articles = file('articles/article.dat');
if (count($articles)==0)
{
echo '<div class="noArt"><b><small>There Are No Articles in this Catagory as of Yet</small></b></div>';
}
else
{
$ia = 0;
foreach ($articles as $thisarticle)
{
$thisarticle = trim($thisarticle);
if(!empty($thisarticle))
{
list($artcat,$arttitle,$artsub,$artdesc,$artkeys,$artprimekeys,$artbody,$artauth) = explode("\t",$thisarticle);
if($artcat == $catagory)
{
echo '<div id="artHead"><a href="article.php?articleid='.$ia.'" class="artTitle">'.$arttitle.'</a></div><div id="artDesc">'.$artdesc.' <a href="article.php?articleid='.$ia.'" class="artMore">learn more >>></a></div>';
}
$ia++;
}
}
}
echo '<br><br>';
$i++;
}
}
}
?>
And this is the code to render the template page:
<?php
if(isset($_GET['articleid']))
{
$i=$_GET['articleid'];
$articles = file('articles/article.dat');
$articletoshow = $articles[$i];
$articletoshow = trim($articletoshow);
if(!empty($articletoshow))
{
list($artcat,$arttitle,$artsub,$artdesc,$artkeys,$artprimekeys,$artbody,$artauth) = explode("\t",$articletoshow);
echo '<html><head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">';
echo '<title>'.$artprimekeys.' | '.$arttitle.'</title>';
echo '<meta name="description" content="'.$artdesc.'">';
echo '<meta name="keywords" content="'.$artkeys.'">';
echo '<meta name="author" content="'; include('admin/inc/webmaster.txt'); echo '">';
echo '<meta name="generator" content="'; include('admin/inc/version.txt'); echo '">';
echo '<link rel="StyleSheet" type="text/css" href="style.css">';
echo '</head><body>';
include('header.php');
echo '<!-- startprint -->';
echo '<h1 class="arthead">'.$arttitle.'</h1>';
echo '<h2 class="artsub">'.$artsub.'</h2>';
include('ads/article-render.php');
echo '<div id="author">by '.$artauth.'</div>';
echo $artbody;
echo '<!-- stopprint --><p>';
include('recommend/recommend-link.php');
include('admin/inc/social-bookmark.php');
include('admin/inc/print-it.php');
echo '<div class="adDiv">'; include('ads/mid-render.php'); echo '<div>';
echo 'random';
echo 'cbrss';
echo '<div class="adDiv">'; include('ads/lower-render.php'); echo '<div>';
echo '2nd-rss';
echo '<div class="adDiv">'; include('ads/foot-render.php'); echo '<div>';
include('footer.php');
}
}
?>
Once again, thank you for reviewing my problem. Any help in resolving this issue would be greatly appreciated.
Pete