Jump to content

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


Recommended Posts

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
[code]
<?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;
}
}

?>
[/code]
[code]
<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>
[/code]
missing bracket on the second block where you have function ReservePrice($reserve).

change to this:
[code]
<?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";
    }
    }
}
?>
[/code]

btw, did you indent your code?  It'll help prevent this kind of error.
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.
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:
[list]
[*]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.
[/list]

Ken
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
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");
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.