Jump to content

[SOLVED] News Posting Script Bug


ryld

Recommended Posts

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

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?

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.

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.

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!

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.