Hello, I am very new to php and I just began yesterday. I am having trouble with a script I am writing, and any support would be appreciated.

I personally think it's just my POST data acting up, but I don't know.

The news is all held in a text database located at www.purplenum.com/database/news.txt.

The Add News page in the Admin CP works perfectly fine, and is password locked with a non-debug password (You'll soon see why I say this).

The Edit News page has a debug password of well, password. Here is the source for all of the pages, and go to www.purplenum.com/admin/edit_news.php, enter the password, submit it, and you'll see what the problem is.

www.purplenum.com/admin/edit_news.txt
www.purplenum.com/admin/edit_news_auth.txt
www.purplenum.com/admin/edit_news_post.txt

The above files are all of the source files for the pages, maybe someone can see something wrong with it because I have no clue what is wrong.

The reason I have a seperate auth page is because when I used auth on the top of my edit_news_post.php page it ALWAYS returned with an incorrect password. So I think this problem I'm having now is the result of a POST data problem.

Thank you for your time, and hopefully someone can see something I'm missing. And please don't flame me if I did something horribly stupid, I'm still new to this.

Edit: Removing the auth page fixes the problem, but I need password authentification somehow. Any ideas?

    Sorry but it's all very confusing. 🙁 Code we see the code for final_news_edit.php?

      brandtj wrote:

      Sorry but it's all very confusing. 🙁 Code we see the code for final_news_edit.php?

      I haven't made that page yet, that isn't what I need help troubleshooting. (The right now only has two lines of code and not even the '?>' bit)

      I need some way to authenticate my $_POST['password'] variable, kind of like I do in www.purplenum.com/admin/add_news.php, but without screwing up my POST Data.

        You need to have a complete script before you can test it and see if there are problems.

          Well, all that the "final" php page would do is the fopen(); and stuff, write now I'm just trying to get the selection of which news to edit to work. I'd rather move step by step rather than going through a whole huge thing getting problems one at a time.

            Near as I can tell, what you have works... I visited the webpage and couldn't see any errors. 😕

              Well, at the moment I'm working on password Auth because everytime I authenticate the password it tends to mess up my POST data. Does anyone know the cause of this?

              (I'm using an if statement, with the == operator to compare two strings)

              Edit: Using === to compare two strings seemed to fix it, but now I'm in a quandry. I know to post new news I would set a variable to $holdData = file_get_contents('../database/news.txt');, but how would I go about editing a certain bit of it? Is there some way to grab all the data BEFORE and AFTER what I want to edit, and then put it back into the file in that order?

                I can't see any reason that that might happen... when I loaded the page and typed in the password it worked fine. 😕

                  Sorry if I move a bit fast for forums, I've been troubleshooting this myself to no avail so some friends are helping me on AIM/MSN. So I may be able to figure some things out myself, coming to a forum was kind of a last resort though.

                  But, I have this all working fine now, how do I go about editing an area in the MIDDLE of my file?

                    In case you are not familiar with "scope" which I am assuming you are not, that means that any variable you declare outside of a function is available to anything outside of functions. Any variable you declare inside of a function is only available inside your function. In order to be able to reach a variable outside of a function, you need to make it a global variable.

                    <?php
                    	$newsFile = '../database/news.txt';
                    	$explosion = explode('||', $newsFile);
                    	$openBottom = fopen('../database/news_bottom.txt', 'w+');
                    	function writeNews($recurse)
                    		{
                    		global $openBottom;
                    
                    	fwrite($openBottom, $explosion[$recurse]);
                    	fwrite($openBottom, '\n||\n');
                    // etc...

                    Let me know if that fixes it!

                      <?php
                      	function writeNews()
                      		{
                      			global $storeMe;
                      			global $title;
                      			global $content;
                      			global $poster;
                      			global $title;
                      			$count = 0;
                      			$explodeMe = file_get_contents("../database/news.txt");
                      			$openBottom = fopen("../database/news_bottom.txt", "w+");
                      			$explosion = explode("||", $explodeMe);
                      				while ($count < $storeMe)
                      					{
                      					fwrite($openBottom, $explosion[$count]);
                      					fwrite($openBottom, "\n||\n");
                      					$count++;
                      					}
                      			fclose($openBottom);
                      			$openTop = fopen("../database/news_top.txt", "w+");
                      			$storeMe += 4;
                      				while ($explosion[$storeMe])
                      					{
                      					$explosion = explode("||", $explodeMe);
                      					fwrite($openTop, $explosion[$storeMe]);
                      					fwrite($openTop, "\n||\n");
                      					$storeMe++;
                      					}
                      			fclose($openTop);
                      			$reWrite = fopen("../database/news.txt", "w");
                      			$newsBottom = file_get_contents("../database/news_bottom.txt");
                      			$newsTop = file_get_contents("../database/news_top.txt");
                      			fwrite($reWrite, $newsBottom);
                      			fwrite($reWrite, $title);
                      			fwrite($reWrite, "\n||\n");
                      			fwrite($reWrite, $content);
                      			fwrite($reWrite, "\n||\n");
                      			fwrite($reWrite, $poster);
                      			fwrite($reWrite, "\n||\n");
                      			fwrite($reWrite, $date);
                      			fwrite($reWrite, "\n||\n");
                      			fwrite($reWrite, $newsTop);
                      			fclose($reWrite);
                      		}
                      	writeNews();
                      ?>

                      I got everything working except this script refuses to write to my news_bottom.txt, and when it writes to news_top.txt is writes starting from the edited news on (Thus making the edited news appear twice, deleting whatever comes before it).

                        Write a Reply...