nikhilnaik Posted September 1, 2011 Share Posted September 1, 2011 i get the following error in my site.... Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/billi/public_html/code/includes/form.php on line 1 the coding of form.php is as follows <? class Form { var $values = array(); //Holds submitted form field values var $errors = array(); //Holds submitted form error messages var $num_errors; //The number of errors in submitted form /* Class constructor */ function Form(){ /** * Get form value and error arrays, used when there * is an error with a user-submitted form. */ if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){ $this->values = $_SESSION['value_array']; $this->errors = $_SESSION['error_array']; $this->num_errors = count($this->errors); unset($_SESSION['value_array']); unset($_SESSION['error_array']); } else{ $this->num_errors = 0; } } /** * setValue - Records the value typed into the given * form field by the user. */ function setValue($field, $value){ $this->values[$field] = $value; } /** * setError - Records new form error given the form * field name and the error message attached to it. */ function setError($field, $errmsg){ $this->errors[$field] = $errmsg; $this->num_errors = count($this->errors); } /** * value - Returns the value attached to the given * field, if none exists, the empty string is returned. */ function value($field){ if(array_key_exists($field,$this->values)){ return htmlspecialchars(stripslashes($this->values[$field])); }else{ return ""; } } /** * error - Returns the error message attached to the * given field, if none exists, the empty string is returned. */ function error($field){ if(array_key_exists($field,$this->errors)){ return "<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>"; }else{ return ""; } } /* getErrorArray - Returns the array of error messages */ function getErrorArray(){ return $this->errors; } }; ?> plz help! Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/ Share on other sites More sharing options...
mjahkoh Posted September 1, 2011 Share Posted September 1, 2011 I dont know which php version you are using but please make your first line as <?php as apposed to <? Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/#findComment-1264207 Share on other sites More sharing options...
trq Posted September 1, 2011 Share Posted September 1, 2011 Besides that code being horribly out of date, i don't see anything wrong with it. Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/#findComment-1264208 Share on other sites More sharing options...
AyKay47 Posted September 1, 2011 Share Posted September 1, 2011 are you sure this is the relevant code..? I don't see a ";" on line one, and yes make sure that short tags are enabled in your php.ini before using them.. it's a better practice to not use them at all. Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/#findComment-1264226 Share on other sites More sharing options...
jamesxg1 Posted September 1, 2011 Share Posted September 1, 2011 Sorted and cleaned! <?php class Form { public $values = array(); public $errors = array(); public $num_errors; public function Form() { if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])) { $this->values = $_SESSION['value_array']; $this->errors = $_SESSION['error_array']; $this->num_errors = count($this->errors); unset($_SESSION['value_array']); unset($_SESSION['error_array']); } else { $this->num_errors = 0; } return true; } public function setValue($field, $value) { $this->values[$field] = $value; return true; } public function setError($field, $errmsg) { $this->errors[$field] = $errmsg; $this->num_errors = count($this->errors); return true; } public function value($field) { if(array_key_exists($field, $this->values)) { return htmlspecialchars(stripslashes($this->values[$field])); } else { return ""; } } public function error($field) { if(array_key_exists($field, $this->errors)) { return "<font size=\"2\" color=\"#ff0000\">" . $this->errors[$field] . "</font>"; } else { return ""; } } public function getErrorArray() { return $this->errors; } } ?> James. Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/#findComment-1264240 Share on other sites More sharing options...
nikhilnaik Posted September 1, 2011 Author Share Posted September 1, 2011 jamesxg1 thnks a lot ... Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/#findComment-1264342 Share on other sites More sharing options...
jamesxg1 Posted September 2, 2011 Share Posted September 2, 2011 jamesxg1 thnks a lot ... My pleasure :-)! Happy coding! James. Quote Link to comment https://forums.phpfreaks.com/topic/246170-parse-error-syntax-error-unexpected-expecting-t_function/#findComment-1264817 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.