Topic: PHP Help

Well, I'm writing a posting script for my blog and I'm getting some errors with this code:

<?php 
include('arrays.php'); 
if (isset($uname)){ 
if ($verify[$uname] == $password) 
{
include("config.php");
  if($submit)
  {//begin of if($submit).
      // Set global variables to easier names
     // and pervent sql injection and apostrophe to break the db.
      $title = mysql_real_escape_string($_POST['title']);
      $newstext = mysql_real_escape_string($_POST['newstext']);
              //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
         // this is the old query \/
         //$result = mysql_query("INSERT INTO news (title, dtime, text1) VALUES ('$title',NOW(),'$text1')",$connect);
                       
         $result = mysql_query("INSERT INTO `news` (`id`, `postdate`, `title`, `newstext`) VALUES (RAND(), NOW(), ''$title'', ''$newstext'')", $connect);
        
          //print success message.
          echo "<b>Thank you! News added Successfully!<br>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
  { ?>
      <br>
      <h3>Post News</h3>
      <form method="post" action="<?php echo $PHP_SELF ?>">
      Title: <input name="title" size="40" maxlength="255"><br />
      Newstext: <textarea name="newstext"  rows="7" cols="30"></textarea><br />
      <input type="submit" name="submit" value="Add News"><input type="reset" name="reset" value="Reset News">
      </form>
      <?
}
?>

The error is: Parse error: parse error, unexpected $ in /home/lnorton/public_html/tiger/blog/post.php on line 40

[img]http://www.devillous.com/css/images/footer.gif[/img]

Re: PHP Help

Not really sure...
Perhaps because you use a short tag after </form>? Try using the full <?php tag

3 (edited by Gizzmo 2005-02-17 01:43)

Re: PHP Help

i beleave you need to close the else statement you didnt do that.

EDIT: actuly there is two things you need to close

Re: PHP Help

I don't see what you're talking about closing the else statement, or the other, can you please elaborate?

[img]http://www.devillous.com/css/images/footer.gif[/img]

5

Re: PHP Help

The final } closes the first "if" not the "else" (or vice versa). You need another } at the bottom.

Re: PHP Help

I added that, and it's the exact same error.

<?php 
include('arrays.php'); 
if (isset($uname)){ 
if ($verify[$uname] == $password) 
{
include("config.php");
  if($submit)
  {//begin of if($submit).
      // Set global variables to easier names
     // and pervent sql injection and apostrophe to break the db.
      $title = mysql_real_escape_string($_POST['title']);
      $newstext = mysql_real_escape_string($_POST['newstext']);
              //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
             // this is the old query \/
         //$result = mysql_query("INSERT INTO news (title, dtime, text1) VALUES ('$title',NOW(),'$text1')",$connect);
                       
         $result = mysql_query("INSERT INTO `news` (`id`, `postdate`, `title`, `newstext`) VALUES (RAND(), NOW(), ''$title'', ''$newstext'')", $connect);
        
          //print success message.
          echo "<b>Thank you! News added Successfully!<br>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 { ?>
      <br>
      <h3>Post News</h3>
      <form method="post" action="<?php echo $PHP_SELF ?>">
      Title: <input name="title" size="40" maxlength="255"><br />
      Newstext: <br />
      <textarea name="newstext"  rows="7" cols="30"></textarea><br />
      <input type="submit" name="submit" value="Submit"><input type="reset" name="reset" value="Reset">
      </form>
<?php
    }
}
?>
[img]http://www.devillous.com/css/images/footer.gif[/img]

Re: PHP Help

oh yea just noticed this too.....you also need to close this

if (isset($uname)){

other than that i dont see any other errors

Re: PHP Help

What have we learned today? http://en.wikipedia.org/wiki/Indent_style

"Programming is like sex: one mistake and you have to support it for the rest of your life."