kenwvs Posted July 13, 2006 Share Posted July 13, 2006 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]<?phpfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/ Share on other sites More sharing options...
hvle Posted July 13, 2006 Share Posted July 13, 2006 you got error before this function.you might want to post the entired script up.hehehe Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57290 Share on other sites More sharing options...
kenwvs Posted July 13, 2006 Author Share Posted July 13, 2006 [code]<HTML><BODY><?phpfunction isDigits($element) { //numbers only return !preg_match ("/[^0-9]/", $element);}?><?phpfunction Dollars($element) { //numbers and decimal return !preg_match ("/[^0-9]./", $element);}?><?phpfunction isLetters($element) { //letters only return !preg_match ("/[^A-z]/", $element);}?><?phpfunction LetandNumOnly($element) { //Letters and Numbers return !preg_match ("/[^A-z0-9]/", $element); //with No Spaces}?><?phpfunction LettersAndDigits($element) { //Letters, Numbers return !preg_match ("/[^A-z0-9 ]/", $element); //and Spaces}?><?phpfunction Variable($element) { //letters, numbers, spaces return !preg_match ("/[^A-z0-9,. ]/", $element);//commas and periods only}?><?phpfunction checkLength($string, $min, $max) { //Check the Length $length = strlen ($string); //min and max if (($length < $min) || ($length > $max)) { return FALSE; } else { return TRUE; }}?><?phpfunction 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); }}?><?phpfunction checkURL($url) { //check valid URL Format return preg_match ("/http:\/\/(.*)\.(.*)/i", $url);}?><?phpfunction 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;}?><?phpfunction 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);}?><?phpfunction 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); }}?><?phpfunction 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);}?><?phpfunction 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!";}}?><?phpfunction 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";}}?><?phpfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57292 Share on other sites More sharing options...
hvle Posted July 13, 2006 Share Posted July 13, 2006 missing bracket on the second block where you have function ReservePrice($reserve). change to this:[code]<?phpfunction 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. Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57300 Share on other sites More sharing options...
kenwvs Posted July 13, 2006 Author Share Posted July 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57302 Share on other sites More sharing options...
brown2005 Posted July 13, 2006 Share Posted July 13, 2006 wat ya mean by indent? Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57304 Share on other sites More sharing options...
kenwvs Posted July 13, 2006 Author Share Posted July 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57306 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57307 Share on other sites More sharing options...
hvle Posted July 13, 2006 Share Posted July 13, 2006 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;}} Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57308 Share on other sites More sharing options...
brown2005 Posted July 13, 2006 Share Posted July 13, 2006 ooo i see... i do that anyway.. thank god.. lol.... Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57309 Share on other sites More sharing options...
kenwvs Posted July 13, 2006 Author Share Posted July 13, 2006 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 helpKen Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57312 Share on other sites More sharing options...
hvle Posted July 13, 2006 Share Posted July 13, 2006 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"); Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57314 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14479-parse-error-parse-error-unexpected-end-in-file-location-resolved/#findComment-57315 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.