Jump to content


Photo

Parse error: parse error, unexpected $end in (FILE LOCATION) RESOLVED


  • Please log in to reply
12 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 13 July 2006 - 01:07 PM

This is the last function in my file, and this error is coming up on the last line, which contains just the ?>
If I remove this function, then it gives me the error at the end of the previous one, so I am thinking it might have to do with not ending the file.  I have tried putting </Body> and </HTML> as they are also at the start of the file, and then I tried deleting them from the start and end, but no luck....Looking for an idea on this.

thanks,

Ken
<?php
function ItemCategory($category)    {          // Verify Valid Category
$item_category = $_POST['item_category'];
if($item_category == "000")//assumes you gave it the value 000
{
echo "Please select a valid category";
exit;
}
}

?>


#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 01:16 PM

you got error before this function.
you might want to post the entired script up.
hehehe
Life's too short for arguing.

#3 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 13 July 2006 - 01:18 PM

<HTML>
<BODY>

<?php
function isDigits($element) {                       //numbers only
  return !preg_match ("/[^0-9]/", $element);
}
?>

<?php
function Dollars($element) {                        //numbers and decimal
  return !preg_match ("/[^0-9]./", $element);
}
?>

<?php
function isLetters($element) {                      //letters only
  return !preg_match ("/[^A-z]/", $element);
}
?>

<?php
function LetandNumOnly($element) {                  //Letters and Numbers
  return !preg_match ("/[^A-z0-9]/", $element);     //with No Spaces
}
?>

<?php
function LettersAndDigits($element) {               //Letters, Numbers
  return !preg_match ("/[^A-z0-9 ]/", $element);   //and Spaces
}
?>

<?php
function Variable($element) {                       //letters, numbers, spaces
  return !preg_match ("/[^A-z0-9,. ]/", $element);//commas and periods only
}
?>

<?php
function checkLength($string, $min, $max) {         //Check the Length
  $length = strlen ($string);                       //min and max
  if (($length < $min) || ($length > $max)) {
    return FALSE;
  } else {
    return TRUE;
  }
}
?>

<?php
function checkMailCode($code, $country) {           //Check Postal Code
  $code = preg_replace("/[\s|-]/", "", $code);      //by Country
  $length = strlen ($code);
  switch (strtoupper ($country)) {
    case 'US':
      if (($length <> 5) && ($length <> 9)) {
        return FALSE;
      }
      return isDigits($code);
    case 'CA':
      if ($length <> 6) {
        return FALSE;
      }
      return preg_match ("/([A-z][0-9]){3}/", $code);
  }
}
?>

<?php
function checkURL($url) {                           //check valid URL Format
  return preg_match ("/http:\/\/(.*)\.(.*)/i", $url);
}
?>

<?php
function checkURLandConnect($url) {                 //Check Valid URL and
  if (!preg_match ("/http:\/\/(.*)\.(.*)/i", $url)) {//Confirm by Connecting
    return FALSE;
  }
  $parts = parse_url($url);
  $fp = fsockopen($parts['host'], 80, $errno, $errstr, 10);
  if(!$fp) {
    return FALSE;
  }
  fclose($fp);
  return TRUE;
}
?>

<?php
function checkEmail($email) {                       //Check Email Format
  $pattern = "/^[A-z0-9\._-]+"
         . "@"
         . "[A-z0-9][A-z0-9-]*"
         . "(\.[A-z0-9_-]+)*"
         . "\.([A-z]{2,6})$/";
  return preg_match ($pattern, $email);
}
?>

<?php
function EmailorEmpty($email) {                     //Check Email Format
    if(empty($email)) {                             //or empty field
        return true;
    } else {
        $pattern = "/^[A-z0-9\._-]+"
        . "@"
        . "[A-z0-9][A-z0-9-]*"
        . "(\.[A-z0-9_-]+)*"
        . "\.([A-z]{2,6})$/";
        return preg_match ($pattern, $email);
    }
}
?>

<?php
function checkPassword($password) {                 //check password for minimum
  $length = strlen ($password);                     //of 8 characters and must
  if ($length < 8) {                                //have a number between letters
    return FALSE;                                   //and a variation of letters
  }
  $unique = strlen (count_chars ($password, 3));
  $difference = $unique / $length;
  echo $difference;
  if ($difference < .60) {
    return FALSE;
  }
  return preg_match ("/[A-z]+[0-9]+[A-z]+/", $password);
}
?>

<?php
function BidIncrement($bid)   {
$bid_increment = $_POST['bid_increment'];  //function for bid_increment only
$item_type = $_POST['item_type'];
if($item_type == "auction" or $item_type=="dutch auction")
{
if(!(is_numeric($bid_increment))
OR empty($bid_increment)){
  echo "You have not entered a valid Bid Increment";
  exit;
  }
  else{
  echo "Valid bid increment";
  }
}elseif($item_type == "fixed price" OR $item_type="classified"){
  if(!empty($bid_increment)){
    echo "Bid Increments are not valid for this type of Listing!";
}
}

?>

<?php
function ReservePrice($reserve)     {
$reserve_price = $_POST['reserve_price'];  //function for reserve_price only
$item_type = $_POST['item_type'];
if($item_type == "Auction" or $item_type=="Dutch Auction")
{
if(!(is_numeric($reserve_price))
OR empty($reserve_price)){
  echo "You have not entered a Valid Reserve Bid or Starting Price";
  exit;
  }
  else{
  echo "Valid bid increment";
  }
}elseif($item_type == "Fixed Price" OR $item_type="Classified Ad"){
  if(!empty($reserve_price)){
    echo "A Reserve Bid or Starting Price cannot be entered for this auction type";
}
}

?>
<?php
function ItemCategory($category)    {          // Verify Valid Category
$item_category = $_POST['item_category'];
if($item_category == "000")//assumes you gave it the value 000
{
echo "Please select a valid category";
exit;
}
}

?>

</BODY>
</HTML>


#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 01:28 PM

missing bracket on the second block where you have function ReservePrice($reserve).

change to this:
<?php
function ReservePrice($reserve)     {
    $reserve_price = $_POST['reserve_price'];  //function for reserve_price only
    $item_type = $_POST['item_type'];
    if($item_type == "Auction" or $item_type=="Dutch Auction")
    {
    if(!(is_numeric($reserve_price))
    OR empty($reserve_price)){
      echo "You have not entered a Valid Reserve Bid or Starting Price";
      exit;
      }
      else{
      echo "Valid bid increment";
      }
    }elseif($item_type == "Fixed Price" OR $item_type="Classified Ad"){
      if(!empty($reserve_price)){
        echo "A Reserve Bid or Starting Price cannot be entered for this auction type";
    }
    }
}
?>

btw, did you indent your code?  It'll help prevent this kind of error.
Life's too short for arguing.

#5 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 13 July 2006 - 01:31 PM

On the program I did indent, haven't done this one yet, as I have been up all night trying to figure it all out.  This is the first script I have really written, and am going to indent this yet.

#6 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 13 July 2006 - 01:32 PM

wat ya mean by indent?

#7 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 13 July 2006 - 01:35 PM

look at the original script posted and how all the brackets are at the edge, and then look at the example with the correction, how the brackets are indented.  The indentations all go together with the bracket, so you can then see where the brackets start and stop, and you can tell if you are missing one.

#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 01:35 PM

An error like this usually means that there are unbalanced curly braces somewhere in the file. Indent your code correctly and it will probably show very clearly. Indent your code as you write it, not after the fact. Much easier.

A few comments on the coding style:
  • Since this looks like a file that will be included in another script (I don't see any mainline code), you don't need any HTML tags.
  • There are many areas where you have a terminating PHP tag "?>" followed immediately by an opening PHP tag "<?php". Those are redundant and may actaully slow the processing of your script. Just have on "<?php" at the start of your script  and one "?>" at the end.

Ken

#9 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 01:37 PM

for brown2005:
this is indented code:

function func()
{
  $var = 1;
  if ($var == 1)
  {
      $var = 2;
  }
}


unindented code:

function func()
{
$var = 1;
if ($var == 1)
{
$var = 2;
}
}

Life's too short for arguing.

#10 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 13 July 2006 - 01:37 PM

ooo i see... i do that anyway.. thank god.. lol....

#11 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 13 July 2006 - 01:42 PM

Thanks for the tips, they are appreciated.  A question for clarification please.

You are correct that these functions will be used with another script (different page).  Is it a good idea to include these in the same page, or keep them separate.  I followed through a tutorial on form validation (from a different site) and they suggested keeping it separate so I can reuse these functions on different pages in the future.

If these functions will be used to validate a page, but each one is independent of the others, can I still eliminate all of the <?php and ?> tags?

Thanks for the help

Ken

#12 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 01:45 PM

you very should create a file and put all the functions that is used by several cripts.

like, create a file called functions.php and put all of them in there.
when using it use require_once directive.

require_once("functions.php");
Life's too short for arguing.

#13 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 01:46 PM

When you include a file containing scripts in another script, the whole file is included, not just the functions you use. You only need the first "<?php" and the last "?>".

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users