ryld Posted August 13, 2008 Share Posted August 13, 2008 Hey guys. I'm upgrading a website for some friends and trying to make it easier to manage. I'm by no means a professional, and the code is probably ugly, but here's the problem. I've written a news posting script that connects to a local database and is SUPPOSED to post news. You can view the news posting script HERE. For some reason, I'm getting a portion of the script displayed. It says, "Thank you! News added Successfully! You'll be redirected to Home Page after (4) Seconds"; echo ""; }//end of if($submit). // If the form has not been submitted, display it! else { //begin of else ?>" at the top of the page. This is odd, because it's not the whole script, and it doesn't include the "ECHO" command that starts this. For this reason, I believe PART of the problem lies somewhere within that block of code. The real problem, however, is that for some reason, upon visiting the page initially, it thinks (for some reason) that the SUBMIT button has ALREADY been clicked. Otherwise, this block of code would not begin processing in the first place. Here is what I believe is all relevant information: Server: Windows 2003 Standard, IIS 6.0 PHP: PHP5 (whatever latest release as of this posting is) MySQL: 5.0 Here is the source code: <html> <head> <title>Add News - Kaos Guild Website</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <? include("config.php"); if(isset($_POST['submit'])) { // Begin of if($submit). // Set global variables to easier names // and pervent sql injection and apostrophe to break the db. $title = mysql_escape_string($_POST['title']); $text1 = mysql_escape_string($_POST['text1']); $text2 = mysql_escape_string($_POST['text2']); //check if (title) field is empty then print error message. if(!$title){ //this means If the title is really empty. echo "Error: News title is a required field. Please fill it."; exit(); //exit the script and don't do anything else. }// end of if //run the query which adds the data gathered from the form into the database $result = mysql_query("INSERT INTO news (title, dtime, text1, text2) VALUES ('$title',NOW(),'$text1','$text2')",$connect); //print success message. echo "Thank you! News added Successfully!You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=../index.php>"; }//end of if($submit). // If the form has not been submitted, display it! else { //begin of else ?> <div id="holder"> <br> <h3>::Add News</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <table> <tr><th>Title: </th><td><input name="title" size="42" maxlength="255"></td></tr> <tr><th>Post Content: </th><td><textarea name="text1" rows="7" cols="30"></textarea></td></tr> <tr><td></td><td id="submit"><input type="submit" name="submit" value="Add News"></td></tr> </table> </form> <? } //end of else ?> </div> </body> </html> I know that it has nothing to do with the CSS. My PHP editor is not reporting any syntax errors. Connecting to the database is not producing any errors. To top it all off, and to make things extremely weird, I have this script on another website (which, as a professional production environment I can't disclose), and it functions properly. The only difference that it could be is how they may have PHP configured since I have no control over that. I have every standard (with the installation) PHP module loaded, too, just in case. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/ Share on other sites More sharing options...
phpcodec Posted August 13, 2008 Share Posted August 13, 2008 It looks like your site is not parsing PHP at all Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616003 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 I can confirm my website is parsing PHP. If I change my database settings in the PHP config to an incorrect database, I get an error saying "Could not select database." Any other ideas? Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616007 Share on other sites More sharing options...
genericnumber1 Posted August 13, 2008 Share Posted August 13, 2008 Yes, if you view your source you can see that it is not being parsed at all... it's just not all being displayed because the browser is having trouble coping with the < in <? and is counting it as a tag. This is, of course, all BEFORE the redirect your have in there... plus, if it can't select the database, how do you expect to query? Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616010 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Can you upload a phpinfo script and let me have a look at it for a second? P.S: Also, don't use short tags. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616011 Share on other sites More sharing options...
phpcodec Posted August 13, 2008 Share Posted August 13, 2008 It is defnitley your host / site not parsing PHP becuase i uploaded your source code to my site and it works fine for me Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616012 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 also try changing successful, You'll to successful, You%27ll It may be parsing PHP but not the short tags change <? to <?php Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616013 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 Okay. Here are my thoughts: It has to be parsed in some way because my config file is written in PHP, and if I use false values in the config file, I get the appropriate error message saying value blah blah blah is invalid. I did a phpinfo(); it returns nothing. Visit 66.168.106.57/test.php to see. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616018 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 Then there is a problem with the PHP (or Apache) installation. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616021 Share on other sites More sharing options...
phpcodec Posted August 13, 2008 Share Posted August 13, 2008 right then, so it seems that your site / host is not letting you pass php, try replace the PHP tag <? to <?php Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616023 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 To be clear test.php should look something like this <?php //ALLWAYS use <?php not <? phpinfo(); ?> Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616026 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 How can I troubleshoot the installation? I'm getting conflicting reports. phpinfo() doesn't return anything, BUT In my config.php file, if I use the proper credentials, I recieve no output (this is expected). However, if I use the incorrect credentials, I receive output informing me that the database cannot be selected (expected, as I changed the dbname variable to a nonexistant database). This means that in order for it to display this error message under only a specific condition, PHP is doing SOMETHING. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616027 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 Unkwntech: Thanks. Changing from the short tag causes PHPINFO() to perform as expected. I also tried changing to from short to <?php in the add file, however now it simply does not load at all. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616031 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 add set_ini('display_errors', '1'); error_reporting(E_ALL); to the TOP of the file. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616034 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 I'm assuming you meant to add it to the top of the very first PHP block in add.php. I did this, and the web page still will not load. If I change the opening PHP tag to short, though, it loads...but with the previously mentioned error. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616037 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 I'm thinking that there is a much bigger problem, then just the script. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616040 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 I was afraid so. I've checked everything I've seen against tutorials and FAQs, though, and as far as I know I have PHP properly configured with IIS. Looking at 66.168.106.57/test.php, do you see anything wrong? You guys are great, by the way...extremely fast responses. Thanks! Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616043 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 Aside from the fact that you are using IIS(joking well not really) no. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616050 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 Yeah yeah...I know all the IIS and Windows jokes out there. If I didn't have classes that cover Windows Server in January, I wouldn't be bothering. Oh, and here's another monkey wrench: phpBB functions flawlessly. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616053 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Short tags are off, you need to use full ones. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616056 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 DarkWater- As mentioned previously, switching to full tags does not solve the problem. If anything, it makes it worse. Using full tags prevents the page from loading at all. That is its current behavior because I have full tags on. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616057 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 You must have a syntax error then I guess? Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616063 Share on other sites More sharing options...
ryld Posted August 13, 2008 Author Share Posted August 13, 2008 DarkWater: You would think so, considering all other PHP scripts are functioning properly and as expected. They even produce the expected output when I change variables to point to things incorrectly. However, first, I don't see any syntax errors and no one has pointed any out. Second, this script works (more or less unchanged) on a production server (not the same server). Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616067 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Check if that server has short tags on. If it does, well, that explains why it works. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616073 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 My guess is that the production server is a linux box, PHP on windows never seems to display errors, I don't know about IIS but I know apache had a path/to/apache/logs/error.log that contains the PHP errors find an check that file. Link to comment https://forums.phpfreaks.com/topic/119570-solved-news-posting-script-bug/#findComment-616076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.