PHP - Call A Class And Function In Another Function
Hi I have a table class and functions I want to call in another function but can't get it working. Some help will be very welcome.
It seesm that the new table class is not working in this function if I pass the values to it, I have tested the class, it does get the post values I post to it so $_POST['id'] are being received as well as all the other $_POST's but the table class and find function is not working, it works fine if I don't put it in a function.. function edit() { if (isset($error)){ $error.="Please fix the error(s) above";} else { if ($_POST['id'] <> "") { $update =& new table($db, 'publisher'); $update->find($_POST['id']); $update->name = $_POST['name']; $update->url = $_POST['url']; $update->contact = $_POST['contact']; $update->address = $_POST['address']; $update->phone = $_POST['phone']; $update->email = $_POST['email']; $update->save(); $error = "The Publisher has been edited"; } } } Similar TutorialsHi I'm setting up my own framework for a project. I was coming to the point of completion and thought up of a new idea. Is it possible to call a function like this from a class: class myClass { function func($param) { echo "Hello world". $param; } } $class = 'myClass'; $func = "func(' It\'s time to partey!')"; $$class = new $class; $$class->$func; Thanks for any help! Im working with php 5.1.6. With xampp 1.5.14.
Im also working on a stock application. If I want to say add stock product (add_stock.php) this error is generated on screen. It seems to refer to a function in ump.class.php
Here we go,
ump.class.php
<?php /** * GUMP - A fast, extensible PHP input validation class * * @author Sean Nieuwoudt (http://twitter.com/SeanNieuwoudt) * @copyright Copyright (c) 2011 Wixel.net * @link http://github.com/Wixel/GUMP * @version 1.0 */ class GUMP { // Validation rules for execution protected $validation_rules = array(); // Filter rules for execution protected $filter_rules = array(); // Instance attribute containing errors from last run protected $errors = array(); // ** ------------------------- Validation Data ------------------------------- ** // public static $basic_tags = "<br><p><a><strong><b><i><em><img><blockquote><code><dd><dl><hr><h1><h2><h3><h4><h5><h6><label><ul><li><span><sub><sup>"; public static $en_noise_words = "about,after,all,also,an,and,another,any,are,as,at,be,because,been,before, being,between,both,but,by,came,can,come,could,did,do,each,for,from,get, got,has,had,he,have,her,here,him,himself,his,how,if,in,into,is,it,its,it's,like, make,many,me,might,more,most,much,must,my,never,now,of,on,only,or,other, our,out,over,said,same,see,should,since,some,still,such,take,than,that, the,their,them,then,there,these,they,this,those,through,to,too,under,up, very,was,way,we,well,were,what,where,which,while,who,with,would,you,your,a, b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,$,1,2,3,4,5,6,7,8,9,0,_"; // ** ------------------------- Validation Helpers ---------------------------- ** // /** * Shorthand method for inline validation * * @param array $data The data to be validated * @param array $validators The GUMP validators * @return mixed True(boolean) or the array of error messages */ public static function is_valid(array $data, array $validators) { $gump = new Gump(); $gump->validation_rules($validators); if($gump->run($data) === false) { return $gump->get_readable_errors(false); } else { return true; } } /** * Magic method to generate the validation error messages * * @return string */ public function __toString() { return $this->get_readable_errors(true); } /** * Perform XSS clean to prevent cross site scripting * * @static * @access public * @param array $data * @return array */ public static function xss_clean(array $data) { foreach($data as $k => $v) { $data[$k] = filter_var($v, FILTER_SANITIZE_STRING); } return $data; } /** * Getter/Setter for the validation rules * * @param array $rules * @return array */ public function validation_rules(array $rules = array()) { if(!empty($rules)) { $this->validation_rules = $rules; } else { return $this->validation_rules; } } /** * Getter/Setter for the filter rules * * @param array $rules * @return array */ public function filter_rules(array $rules = array()) { if(!empty($rules)) { $this->filter_rules = $rules; } else { return $this->filter_rules; } } /** * Run the filtering and validation after each other * * @param array $data * @return array * @return boolean */ public function run(array $data) { $data = $this->filter($data, $this->filter_rules()); $validated = $this->validate( $data, $this->validation_rules() ); if($validated !== true) { return false; } else { return $data; } } /** * Sanitize the input data * * @access public * @param array $data * @return array */ public function sanitize(array $input, $fields = NULL, $utf8_encode = true) { $magic_quotes = (bool)get_magic_quotes_gpc(); if(is_null($fields)) { $fields = array_keys($input); } foreach($fields as $field) { if(!isset($input[$field])) { continue; } else { $value = $input[$field]; if(is_string($value)) { if($magic_quotes === TRUE) { $value = stripslashes($value); } if(strpos($value, "\r") !== FALSE) { $value = trim($value); } if(function_exists('iconv') && function_exists('mb_detect_encoding') && $utf8_encode) { $current_encoding = mb_detect_encoding($value); if($current_encoding != 'UTF-8' && $current_encoding != 'UTF-16') { $value = iconv($current_encoding, 'UTF-8', $value); } } $value = filter_var($value, FILTER_SANITIZE_STRING); } $input[$field] = $value; } } return $input; } /** * Return the error array from the last validation run * * @return array */ public function errors() { return $this->errors; } /** * Perform data validation against the provided ruleset * * @access public * @param mixed $input * @param array $ruleset * @return mixed */ public function validate(array $input, array $ruleset) { $this->errors = array(); foreach($ruleset as $field => $rules) { #if(!array_key_exists($field, $input)) #{ # continue; #} $rules = explode('|', $rules); foreach($rules as $rule) { $method = NULL; $param = NULL; if(strstr($rule, ',') !== FALSE) // has params { $rule = explode(',', $rule); $method = 'validate_'.$rule[0]; $param = $rule[1]; } else { $method = 'validate_'.$rule; } if(is_callable(array($this, $method))) { $result = $this->$method($field, $input, $param); if(is_array($result)) // Validation Failed { $this->errors[] = $result; } } else { throw new Exception("Validator method '$method' does not exist."); } } } return (count($this->errors) > 0)? $this->errors : TRUE; } /** * Process the validation errors and return human readable error messages * * @param bool $convert_to_string = false * @param string $field_class * @param string $error_class * @return array * @return string */ public function get_readable_errors($convert_to_string = false, $field_class="field", $error_class="error-message") { if(empty($this->errors)) { return ($convert_to_string)? null : array(); } $resp = array(); foreach($this->errors as $e) { $field = ucwords(str_replace(array('_','-'), chr(32), $e['field'])); $param = $e['param']; switch($e['rule']) { case 'validate_required': $resp[] = "The <span class=\"$field_class\">$field</span> field is required"; break; case 'validate_valid_email': $resp[] = "The <span class=\"$field_class\">$field</span> field is required to be a valid email address"; break; case 'validate_max_len': if($param == 1) { $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be shorter than $param character"; } else { $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be shorter than $param characters"; } break; case 'validate_min_len': if($param == 1) { $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be longer than $param character"; } else { $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be longer than $param characters"; } break; case 'validate_exact_len': if($param == 1) { $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be exactly $param character in length"; } else { $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be exactly $param characters in length"; } break; case 'validate_alpha': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain alpha characters(a-z)"; break; case 'validate_alpha_numeric': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain alpha-numeric characters"; break; case 'validate_alpha_dash': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain alpha characters & dashes"; break; case 'validate_numeric': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain numeric characters"; break; case 'validate_integer': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain a numeric value"; break; case 'validate_boolean': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain a true or false value"; break; case 'validate_float': $resp[] = "The <span class=\"$field_class\">$field</span> field may only contain a float value"; break; case 'validate_valid_url': $resp[] = "The <span class=\"$field_class\">$field</span> field is required to be a valid URL"; break; case 'validate_url_exists': $resp[] = "The <span class=\"$field_class\">$field</span> URL does not exist"; break; case 'validate_valid_ip': $resp[] = "The <span class=\"$field_class\">$field</span> field needs to contain a valid IP address"; break; case 'validate_valid_cc': $resp[] = "The <span class=\"$field_class\">$field</span> field needs to contain a valid credit card number"; break; case 'validate_valid_name': $resp[] = "The <span class=\"$field_class\">$field</span> field needs to contain a valid human name"; break; case 'validate_contains': $resp[] = "The <span class=\"$field_class\">$field</span> field needs contain one of these values: ".implode(', ', $param); break; case 'validate_street_address': $resp[] = "The <span class=\"$field_class\">$field</span> field needs to be a valid street address"; break; } } if(!$convert_to_string) { return $resp; } else { $buffer = ''; foreach($resp as $s) { $buffer .= "<span class=\"$error_class\">$s</span>"; } return $buffer; } } /** * Filter the input data according to the specified filter set * * @access public * @param mixed $input * @param array $filterset * @return mixed */ public function filter(array $input, array $filterset) { foreach($filterset as $field => $filters) { if(!array_key_exists($field, $input)) { continue; } $filters = explode('|', $filters); foreach($filters as $filter) { $params = NULL; if(strstr($filter, ',') !== FALSE) { $filter = explode(',', $filter); $params = array_slice($filter, 1, count($filter) - 1); $filter = $filter[0]; } if(is_callable(array($this, 'filter_'.$filter))) { $method = 'filter_'.$filter; $input[$field] = $this->$method($input[$field], $params); } else if(function_exists($filter)) { $input[$field] = $filter($input[$field]); } else { throw new Exception("Filter method '$filter' does not exist."); } } } return $input; } // ** ------------------------- Filters --------------------------------------- ** // /** * Replace noise words in a string (http://tax.cchgroup.com/help/Avoiding_noise_words_in_your_search.htm) * * Usage: '<index>' => 'noise_words' * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_noise_words($value, $params = NULL) { $value = preg_replace('/\s\s+/u', chr(32),$value); $value = " $value "; $words = explode(',', self::$en_noise_words); foreach($words as $word) { $word = trim($word); $word = " $word "; // Normalize if(stripos($value, $word) !== FALSE) { $value = str_ireplace($word, chr(32), $value); } } return trim($value); } /** * Remove all known punctuation from a string * * Usage: '<index>' => 'rmpunctuataion' * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_rmpunctuation($value, $params = NULL) { return preg_replace("/(?![.=$'€%-])\p{P}/u", '', $value); } /** * Translate an input string to a desired language [DEPRECIATED] * * Any ISO 639-1 2 character language code may be used * * See: http://www.science.co.il/language/Codes.asp?s=code2 * * @access protected * @param string $value * @param array $params * @return string */ /* protected function filter_translate($value, $params = NULL) { $input_lang = 'en'; $output_lang = 'en'; if(is_null($params)) { return $value; } switch(count($params)) { case 1: $input_lang = $params[0]; break; case 2: $input_lang = $params[0]; $output_lang = $params[1]; break; } $text = urlencode($value); $translation = file_get_contents( "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q={$text}&langpair={$input_lang}|{$output_lang}" ); $json = json_decode($translation, true); if($json['responseStatus'] != 200) { return $value; } else { return $json['responseData']['translatedText']; } } */ /** * Sanitize the string by removing any script tags * * Usage: '<index>' => 'sanitize_string' * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_sanitize_string($value, $params = NULL) { return filter_var($value, FILTER_SANITIZE_STRING); } /** * Sanitize the string by urlencoding characters * * Usage: '<index>' => 'urlencode' * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_urlencode($value, $params = NULL) { return filter_var($value, FILTER_SANITIZE_ENCODED); } /** * Sanitize the string by converting HTML characters to their HTML entities * * Usage: '<index>' => 'htmlencode' * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_htmlencode($value, $params = NULL) { return filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS); } /** * Sanitize the string by removing illegal characters from emails * * Usage: '<index>' => 'sanitize_email' * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_sanitize_email($value, $params = NULL) { return filter_var($value, FILTER_SANITIZE_EMAIL); } /** * Sanitize the string by removing illegal characters from numbers * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_sanitize_numbers($value, $params = NULL) { return filter_var($value, FILTER_SANITIZE_NUMBER_INT); } /** * Filter out all HTML tags except the defined basic tags * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_basic_tags($value, $params = NULL) { return strip_tags($value, self::$basic_tags); } /** * Filter out all SQL Valnurablities * * @access protected * @param string $value * @param array $params * @return string */ protected function filter_mysql_escape($value, $params = NULL) { return mysql_real_escape_string($value); } // ** ------------------------- Validators ------------------------------------ ** // /** * Verify that a value is contained within the pre-defined value set * * Usage: '<index>' => 'contains,value value value' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_contains($field, $input, $param = NULL) { $param = trim(strtolower($param)); $value = trim(strtolower($input[$field])); if (preg_match_all('#\'(.+?)\'#', $param, $matches, PREG_PATTERN_ORDER)) { $param = $matches[1]; } else { $param = explode(chr(32), $param); } if(in_array($value, $param)) { // valid, return nothing return; } else { return array( 'field' => $field, 'value' => $value, 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Check if the specified key is present and not empty * * Usage: '<index>' => 'required' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_required($field, $input, $param = NULL) { if(isset($input[$field]) && trim($input[$field]) != '') { return; } else { return array( 'field' => $field, 'value' => NULL, 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided email is valid * * Usage: '<index>' => 'valid_email' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_email($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_EMAIL)) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value length is less or equal to a specific value * * Usage: '<index>' => 'max_len,240' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_max_len($field, $input, $param = NULL) { if(!isset($input[$field])) { return; } if(function_exists('mb_strlen')) { if(mb_strlen($input[$field]) <= (int)$param) { return; } } else { if(strlen($input[$field]) <= (int)$param) { return; } } return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } /** * Determine if the provided value length is more or equal to a specific value * * Usage: '<index>' => 'min_len,4' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_min_len($field, $input, $param = NULL) { if(!isset($input[$field])) { return; } if(function_exists('mb_strlen')) { if(mb_strlen($input[$field]) >= (int)$param) { return; } } else { if(strlen($input[$field]) >= (int)$param) { return; } } return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } /** * Determine if the provided value length matches a specific value * * Usage: '<index>' => 'exact_len,5' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_exact_len($field, $input, $param = NULL) { if(!isset($input[$field])) { return; } if(function_exists('mb_strlen')) { if(mb_strlen($input[$field]) == (int)$param) { return; } } else { if(strlen($input[$field]) == (int)$param) { return; } } return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } /** * Determine if the provided value contains only alpha characters * * Usage: '<index>' => 'alpha' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_alpha($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!preg_match("/^([a-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ])+$/i", $input[$field]) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value contains only alpha-numeric characters * * Usage: '<index>' => 'alpha_numeric' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_alpha_numeric($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!preg_match("/^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ])+$/i", $input[$field]) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value contains only alpha characters with dashed and underscores * * Usage: '<index>' => 'alpha_dash' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_alpha_dash($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!preg_match("/^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ_-])+$/i", $input[$field]) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a valid number or numeric string * * Usage: '<index>' => 'numeric' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_numeric($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!is_numeric($input[$field])) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a valid integer * * Usage: '<index>' => 'integer' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_integer($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_INT)) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a PHP accepted boolean * * Usage: '<index>' => 'boolean' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_boolean($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } $bool = filter_var($input[$field], FILTER_VALIDATE_BOOLEAN); if(!is_bool($bool)) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a valid float * * Usage: '<index>' => 'float' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_float($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_FLOAT)) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a valid URL * * Usage: '<index>' => 'valid_url' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_url($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_URL)) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if a URL exists & is accessible * * Usage: '<index>' => 'url_exists' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_url_exists($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } $url = str_replace( array('http://', 'https://', 'ftp://'), '', strtolower($input[$field]) ); if(function_exists('checkdnsrr')) { if(!checkdnsrr($url)) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } else { if(gethostbyname($url) == $url) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } } /** * Determine if the provided value is a valid IP address * * Usage: '<index>' => 'valid_ip' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_ip($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_IP) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a valid IPv4 address * * Usage: '<index>' => 'valid_ipv4' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_ipv4($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided value is a valid IPv6 address * * Usage: '<index>' => 'valid_ipv6' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_ipv6($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } if(!filter_var($input[$field], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the input is a valid credit card number * * See: http://stackoverflow.com/questions/174730/what-is-the-best-way-to-validate-a-credit-card-in-php * Usage: '<index>' => 'valid_cc' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_cc($field, $input, $param = NULL) { if(!isset($input[$field]) || empty($input[$field])) { return; } $number = preg_replace('/\D/', '', $input[$field]); if(function_exists('mb_strlen')) { $number_length = mb_strlen($input[$field]); } else { $number_length = strlen($input[$field]); } $parity = $number_length % 2; $total = 0; for($i = 0; $i < $number_length; $i++) { $digit = $number[$i]; if ($i % 2 == $parity) { $digit *= 2; if ($digit > 9) { $digit -= 9; } } $total += $digit; } if($total % 10 == 0) { return; // Valid } else { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the input is a valid human name [Credits to http://github.com/ben-s] * * See: https://github.com/Wixel/GUMP/issues/5 * Usage: '<index>' => 'valid_name' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_valid_name($field, $input, $param = NULL) { if(!isset($input[$field])|| empty($input[$field])) { return; } if(!preg_match("/^([a-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñðòóôõöùúûüýÿ '-])+$/i", $input[$field]) !== FALSE) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } /** * Determine if the provided input is likely to be a street address using weak detection * * Usage: '<index>' => 'street_address' * * @access protected * @param string $field * @param array $input * @return mixed */ protected function validate_street_address($field, $input, $param = NULL) { if(!isset($input[$field])|| empty($input[$field])) { return; } // Theory: 1 number, 1 or more spaces, 1 or more words $hasLetter = preg_match('/[a-zA-Z]/', $input[$field]); $hasDigit = preg_match('/\d/' , $input[$field]); $hasSpace = preg_match('/\s/' , $input[$field]); $passes = $hasLetter && $hasDigit && $hasSpace; if(!$passes) { return array( 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param ); } } } // EOCHere is add_stock.php <?php include_once("init.php"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>POSNIC - Add Stock Category</title> <!-- Stylesheets --> <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet'> <link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="js/date_pic/date_input.css"> <link rel="stylesheet" href="lib/auto/css/jquery.autocomplete.css"> <!-- Optimize for mobile devices --> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <!-- jQuery & JS files --> <?php include_once("tpl/common_js.php"); ?> <script src="js/script.js"></script> <script src="js/date_pic/jquery.date_input.js"></script> <script src="lib/auto/js/jquery.autocomplete.js "></script> <script> /*$.validator.setDefaults({ submitHandler: function() { alert("submitted!"); } });*/ $(document).ready(function() { $("#supplier").autocomplete("supplier1.php", { width: 160, autoFill: true, selectFirst: true }); $("#category").autocomplete("category.php", { width: 160, autoFill: true, selectFirst: true }); // validate signup form on keyup and submit $("#form1").validate({ rules: { name: { required: true, minlength: 3, maxlength: 200 }, stockid: { required: true, minlength: 3, maxlength: 200 }, cost: { required: true, }, sell: { required: true, } }, messages: { name: { required: "Please Enter Stock Name", minlength: "Category Name must consist of at least 3 characters" }, stockid: { required: "Please Enter Stock ID", minlength: "Category Name must consist of at least 3 characters" }, sell: { required: "Please Enter Selling Price", minlength: "Category Name must consist of at least 3 characters" }, cost: { required: "Please Enter Cost Price", minlength: "Category Name must consist of at least 3 characters" } } }); }); function numbersonly(e){ var unicode=e.charCode? e.charCode : e.keyCode if (unicode!=8 && unicode!=46 && unicode!=37 && unicode!=38 && unicode!=39 && unicode!=40 && unicode!=9){ //if the key isn't the backspace key (which we should allow) if (unicode<48||unicode>57) return false } } </script> </script> </head> <body> <!-- TOP BAR --> <?php include_once("tpl/top_bar.php"); ?> <!-- end top-bar --> <!-- HEADER --> <div id="header-with-tabs"> <div class="page-full-width cf"> <ul id="tabs" class="fl"> <li><a href="dashboard.php" class="dashboard-tab">Dashboard</a></li> <li><a href="view_sales.php" class="sales-tab">Sales</a></li> <li><a href="view_customers.php" class=" customers-tab">Customers</a></li> <li><a href="view_purchase.php" class="purchase-tab">Purchase</a></li> <li><a href="view_supplier.php" class=" supplier-tab">Supplier</a></li> <li><a href="view_product.php" class="active-tab stock-tab">Stocks / Products</a></li> <li><a href="view_payments.php" class="payment-tab">Payments / Outstandings</a></li> <li><a href="view_report.php" class="report-tab">Reports</a></li> </ul> <!-- end tabs --> <!-- Change this image to your own company's logo --> <!-- The logo will automatically be resized to 30px height. --> <a href="#" id="company-branding-small" class="fr"><img src="<?php if(isset($_SESSION['logo'])) { echo "upload/".$_SESSION['logo'];}else{ echo "upload/posnic.png"; } ?>" alt="Point of Sale" /></a> </div> <!-- end full-width --> </div> <!-- end header --> <!-- MAIN CONTENT --> <div id="content"> <div class="page-full-width cf"> <div class="side-menu fl"> <h3>Stock Management</h3> <ul> <li><a href="add_stock.php">Add Stock/Product</a></li> <li><a href="view_product.php">View Stock/Product</a></li> <li><a href="add_category.php">Add Stock Category</a></li> <li><a href="view_category.php">view Stock Category</a></li> <li><a href="view_stock_availability.php">view Stock Available</a></li> </ul> </div> <!-- end side-menu --> <div class="side-content fr"> <div class="content-module"> <div class="content-module-heading cf"> <h3 class="fl">Add Stock </h3> <span class="fr expand-collapse-text">Click to collapse</span> <div style="margin-top: 15px;margin-left: 150px"></div> <span class="fr expand-collapse-text initial-expand">Click to expand</span> </div> <!-- end content-module-heading --> <div class="content-module-main cf"> <?php //Gump is libarary for Validatoin if(isset($_POST['name'])){ $_POST = $gump->sanitize($_POST); $gump->validation_rules(array( 'name' => 'required|max_len,100|min_len,3', 'stockid' => 'required|max_len,200', 'sell' => 'required|max_len,200', 'cost' => 'required|max_len,200', 'supplier' => 'max_len,200', 'category' => 'max_len,200' )); $gump->filter_rules(array( 'name' => 'trim|sanitize_string|mysql_escape', 'stockid' => 'trim|sanitize_string|mysql_escape', 'sell' => 'trim|sanitize_string|mysql_escape', 'cost' => 'trim|sanitize_string|mysql_escape', 'category' => 'trim|sanitize_string|mysql_escape', 'supplier' => 'trim|sanitize_string|mysql_escape' )); $validated_data = $gump->run($_POST); $name = ""; $stockid = ""; $sell = ""; $cost = ""; $supplier = ""; $category = ""; if($validated_data === false) { echo $gump->get_readable_errors(true); } else { $name=mysql_real_escape_string($_POST['name']); $stockid=mysql_real_escape_string($_POST['stockid']); $sell=mysql_real_escape_string($_POST['sell']); $cost=mysql_real_escape_string($_POST['cost']); $supplier=mysql_real_escape_string($_POST['supplier']); $category=mysql_real_escape_string($_POST['category']); $count = $db->countOf("stock_details", "stock_name ='$name'"); if($count>1) { $data='Dublicat Entry. Please Verify'; $msg='<p style=color:red;font-family:gfont-family:Georgia, Times New Roman, Times, serif>'.$data.'</p>';// ?> <script src="dist/js/jquery.ui.draggable.js"></script> <script src="dist/js/jquery.alerts.js"></script> <script src="dist/js/jquery.js"></script> <link rel="stylesheet" href="dist/js/jquery.alerts.css" > <script type="text/javascript"> jAlert('<?php echo $msg; ?>', 'POSNIC'); </script> <?php } else { if($db->query("insert into stock_details(stock_id,stock_name,stock_quatity,supplier_id,company_price,selling_price,category) values('$stockid','$name',0,'$supplier',$cost,$sell,'$category')")) { $db->query("insert into stock_avail(name,quantity) values('$name',0)"); $msg=" $name Stock Details Added" ; header("Location: add_stock.php?msg=$msg"); }else echo "<br><font color=red size=+1 >Problem in Adding !</font>" ; } } } if(isset($_GET['msg'])){ $data=$_GET['msg']; $msg='<p style=color:#153450;font-family:gfont-family:Georgia, Times New Roman, Times, serif>'.$data.'</p>';// ?> <script src="dist/js/jquery.ui.draggable.js"></script> <script src="dist/js/jquery.alerts.js"></script> <script src="dist/js/jquery.js"></script> <link rel="stylesheet" href="dist/js/jquery.alerts.css" > <script type="text/javascript"> jAlert('<?php echo $msg; ?>', 'POSNIC'); </script> <?php } ?> <form name="form1" method="post" id="form1" action=""> <table class="form" border="0" cellspacing="0" cellpadding="0"> <tr> <?php $max = $db->maxOfAll("id", "stock_details"); $max=$max+1; $autoid="SD".$max.""; ?> <td><span class="man">*</span>Stock ID:</td> <td><input name="stockid" type="text" id="stockid" readonly maxlength="200" class="round default-width-input" value="<?php echo $autoid; ?>" /></td> <td><span class="man">*</span>Name:</td> <td><input name="name"placeholder="ENTER CATEGORY NAME" type="text" id="name" maxlength="200" class="round default-width-input" value="<?php echo $name; ?>" /></td> </tr> <tr> <td><span class="man">*</span>Cost:</td> <td><input name="cost" placeholder="ENTER COST PRICE" type="text" id="cost" maxlength="200" class="round default-width-input" onkeypress="return numbersonly(event)" value="<?php echo $cost; ?>" /></td> <td><span class="man">*</span>Sell:</td> <td><input name="sell" placeholder="ENTER SELLING PRICE" type="text" id="sell" maxlength="200" class="round default-width-input" onkeypress="return numbersonly(event)" value="<?php echo $sell; ?>" /></td> </tr> <tr> <td>Supplier:</td> <td><input name="supplier" placeholder="ENTER SUPPLIER NAME" type="text" id="supplier" maxlength="200" class="round default-width-input" value="<?php echo $supplier; ?>" /></td> <td>Category:</td> <td><input name="category" placeholder="ENTER CATEGORY NAME" type="text" id="category" maxlength="200" class="round default-width-input" value="<?php echo $category; ?>" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input class="button round blue image-right ic-add text-upper" type="submit" name="Submit" value="Add"> (Control + S) <td align="right"><input class="button round red text-upper" type="reset" name="Reset" value="Reset"> </td> </tr> </table> </form> </div> <!-- end content-module-main --> </div> <!-- end content-module --> </div> <!-- end full-width --> </div> <!-- end content --> <!-- FOOTER --> <div id="footer"> <p>Any Queries email to <a href="mailto:sridhar.posnic@gmail.com?subject=Stock%20Management%20System">sridhar.posnic@gmail.com</a>.</p> </div> <!-- end footer --> </body> </html>now who can tell me what is wrong with the function filter_var() method on line 186 in ump.class.php? I need to call usort from a class function, and I'm puzzled about how to define the comparison function. I've tried to define the comparison function in the same class, but I can't get usort to call it. I found one hint that it will work if I make the comparison function static, but I tried that, and it didn't work for me. If I define the comparison function outside the class, it won't have access to object properties that it needs to operate. The only solution I can think of is to define the comparison function outside the class and put the object properties it needs in globals. Is there a cleaner way to do this? Hi all, I want to call a javascript function from a php function like this: public function Buscar() { $HoraInicio = $_POST['edtHoraInicio']; $HoraFin = $_POST['edtHoraFin']; $FechaInicio = $_POST['edtFec1']; $FechaFin = $_POST['edtFec2']; $FechaMax = $FechaFin." ".$HoraFin.":00"; $FechaMin = $FechaInicio." ".$HoraInicio.":00"; $_GET["FechaMax"] = $FechaMax; $_GET["FechaMin"] = $FechaMin; echo $FechaMin; echo "<script language=javascript>alert('Hi.')</script>"; } but the function Buscar never show the alert but shows the $FechaMin I hopu u guys can help me out with this probem Thanks, Siddhartha This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 I can call the following function successfully as a single php program // Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. Hi
I'm trying to get the layout like i want but it's not easy
I have this file
<?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } if(isset($_POST['submitted'])) { $fgmembersite->PesquisarPorDatas(); } ?> <div id='fg_membersite_content'> <div class="CSSTableGenerator" > //I want the result here </div> <br>I want the result of this $fgmembersite->PesquisarPorDatas(); in "//I want the result here" the r of my code, when the user use the "Pesquisar" button this fucntion is called but the result comes out of my css any help please?? Edited by alphasil, 04 December 2014 - 10:32 AM. I'm writing a program that allows users to input a stock and view a historical price chart. Code is straight out of libchart charting library. Problem is, user is supposed to enter the stock symbol from a form handler (index.php) which then passes the symbol as a variable to the charting function, which doesn't get called at all:
<? php
function index() { chart($_POST['userinput']};
} ?> .
<?php
function chart($stock)
{
$prices=getdata($stock); //returns array of prices from yahoo finance
$data=analyzer($prices); //produces metrics to be charted
graph($data); } ?> //plots the metrics, outputs .html
chart.php works on its own, as I've verified by hardcoding $argv='ibm'; in its code body. But index.php can't seem to call chart.php, as I've verified by including an echo/var_dump line in chart.php (doesn't get executed at all). It doesn't have anything to do with form handling either, as chart('ibm'); doesn't call chart.php either. I don't understand how a 6-line piece of code can be so problematic. All files are in the same folder, btw.
Thanks.
okay in modlogs.php i have a function Code: [Select] <?php function modmenu($page) { ?> <dl><dt class="<?php if ($page == 'modlogs') echo '';else echo 'ust'; ?> LEFT" style='margin-left:5px'><a href='mlogs.php'><b>User Logs</b></a> </dt><dt class="<?php if ($page == 'modlogs1') echo '';else echo 'ust'; ?> LEFT"><a href="modlogs1.php">Topic/Forum Actions</a></dt> <dd> <?php } ?> in modlogs1.php i try to echo Code: [Select] modmenu('modlogs1'); to show the menu but i get unidentified function? lol isn't functions global wtf? Is this even possible? I'm trying to call function nameGen from in the function nameGen but I just get an error saying cannot redeclare. I only want it to return $newName when it is not in the array $takenVals. can this only be done with another loop and a constant somewhere? Code: [Select] $newVarVals = array(); $takenVals = array(); $varCount = count($varArray); // contents are set else where and is fine for($i = 0 ; $i < $varCount; ++ $i) { function nameGen(&$varCount,&$takenVals){ $newName = rand(0,$varCount); if(in_array($newName,$takenVals)) { nameGen(&$varCount,&$takenVals); } else{ return $newName; } } $newName = nameGen(&$varCount,&$takenVals); $takenVals[] = $newName; $newNameToKeep = '$_'.$newName; $newVarVals[] = array('oldName' => $varArray[$i], 'newName' => $newNameToKeep); } error: Cannot redeclare nameGen() Hi im new to php Im excellent in C# more but lets not go into that I was wondering how to call this function. What am i doing wrong.. <?php if(isset($_POST['submit'])) { $startDate = strtotime($_POST['startdate']); $endDate = strtotime($_POST['enddate']); if($startDate != false && $endDate != false) { $startDate = date("y-m-d",$startDate); $endDate = date('y-m-d',$endDate); SearchForBookedRooms($startDate,$endDate); } else { echo "Please select both dates!"; } function SearchForBookedRooms($startDate,$endDate)//Calling this Function Here?? { } } ?> Code: [Select] <html> <center> <form method="post" action=""> <b>Email</b><br><input type="text" name="email"/><br> <b>Password</b><br><input type="password" name="password"/><br> <input type="submit" name="submit" value="Login"/><br> </form> <?php if(isset($_POST['submit'])){ echo echo_post($_POST['email']); function echo_post($postvar){ return $postvar; } } ?> </center> </html> the filename is index.php How come I get the undefined function echo_post on line 14? I know it is probably something simple but I am kind of new to this, if you could help me out that would be great I am getting this error: Parse error: syntax error, unexpected '[', expecting ')' in C:\xampp\htdocs\Work\Store\store.php on line 154 when I run the following code: Code: [Select] function categorySearch($sql) { $res = mysqli_query($this->conn,$sql); $this->results='<table>'; while($cRow = mysqli_fetch_array($res)) { function getCategoryName($cRow[0]) $this->results .= '<tr><td style="border: thin solid #000000;">' . $this->cat_str . '</td></tr>'; } $this->results.='</table>'; return $this->results; } Line 154 refers to this line: function getCategoryName($cRow[0]) Can anyone see what the problem is? I'd like to set my own error handler function to clear some session variables, but I do not want to completely replace php's internal error handler message reporting. Is there any way to mimic the internal error message reporting so I can define my own error handler function. function myErrorHandler(){ unset($_SESSION['var']); // HERE EXECUTE Normal PHP error message reporting } Thanks This is the error that I am getting... Quote <br /> <b>Fatal error</b>: Call to undefined function readChatOnload() in <b>C:\server\xampp\htdocs\php\chat\readChat.php</b> on line <b>18</b><br /> And this is my php file... if(isset($_POST['function'])) { $function = $_POST['function']; switch($function) { case 'readNamesOnload': readNamesOnload(); break; case 'readNamesLoop': readNamesLoop(); break; case 'readChatOnload': readChatOnload(); break; case 'readChatLoop': readChatLoop(); break; } //READ NAMES ONLOAD function readNamesOnload() { die('readNamesOnload'); } //READ NAMES LOOP function readNamesLoop() { die('readNamesLoop'); } //READ CHAT ONLOAD function readChatOnload() { die('readChatOnload'); } //READ CHAT LOOP function readChatLoop() { die('readChatLoop'); } } I don't understand why this is happening. Thanks I've made this code for a very simple registration form practice:
//assign form variables $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; function clean_names($dirty_name) { strip_tags($dirty_name); str_replace(' ', '', $dirty_name); ucfirst(strtolower($dirty_name)); //return $dirty_name; } $names = array($firstname, $lastname, $username); if(isset($_POST['register_button'])) { // WHY IS THIS FUNC CALL NOT WORKING?? foreach($names as $name) { clean_names($name); } echo "First Name: " . $firstname . "<br>"; echo "Last Name: " . $lastname . "<br>"; echo "Username: " . $username . "<br>"; }
The values are returned but they haven't been put through the clean_names function. What's undefined about deposit()? Code: [Select] class BankAccount { private $name; var $balance = 0; private $dep = 0; function __construct() { if (array_key_exists ("deposit" , $_POST)) { $dep = $_POST['deposit']; echo $dep; deposit($dep); } } function deposit($dep) { $balance += $dep; echo $balance; } } Hello, I am new to PHP and have come to a grinding halt in my project. I am attempting to dynamically generate values for Wordpress shortcodes ( [example] ). I have successfully created the shortcodes and am having trouble setting their value. When I call the function that is supposed to return the value for the shortcode, it returns empty. I can however hard code a string and have it returned to the function, thereby manually creating a value for the shortcode. However, because the shortcodes are being generated and filled dynamically, I need this function to work without specific values. I know this may sound like a Wordpress specific question, but I have a feeling it's just my lack of understanding of PHP operations. So, here is the basic layout: The name of the shortcode is generated from within a foreach loop that retrieves the name of custom fields on the post ($keyName). Code: [Select] $custom_field_keys = get_post_custom_keys(); foreach ( $custom_field_keys as $key => $keyName ) { $valuet = trim($keyName); if ( '_' == $valuet{0} ) continue; if ( get_post_meta($thePostID, $keyName, true) ) : $fieldName = get_post_meta($thePostID, $keyName, true); endif; $fieldValue = $_GET["$keyName"]; add_shortcode((string)$keyName, 'myFields'); } The add_shortcode function has two parameters ('name_of_shortcode', 'function_name'): Code: [Select] add_shortcode((string)$keyName, 'myFields'); I need the myFields function to return the value of $fieldValue from within the foreach loop. That's where the problem lies. This doesn't work: Code: [Select] function myFields() { $myString = preg_replace('/[^a-zA-Z\s]/', '', $fieldValue); return $myString; } This does work: Code: [Select] function myFields() { return 'Content to replace the shortcode'; } This code will replace [shortcode] with "Content to replace the shortcode" in the post. The ultimate goal is: when [$keyName] appears anywhere within the post, it will display the content returned by the myFields function ($fieldValue). However, it's not working. I can't seem to pass the value of $fieldValue to the myFields function and thereby return it to add_shortcode. Any help is appreciated and I am awaiting anxiously to answer any questions. Here's all the code together: Code: [Select] function myFields() { $myString = preg_replace('/[^a-zA-Z\s]/', '', $fieldValue); return $myString; } $custom_field_keys = get_post_custom_keys(); foreach ( $custom_field_keys as $key => $keyName ) { $valuet = trim($keyName); if ( '_' == $valuet{0} ) continue; if ( get_post_meta($thePostID, $keyName, true) ) : $fieldName = get_post_meta($thePostID, $keyName, true); endif; $fieldValue = $_GET["$keyName"]; add_shortcode((string)$keyName, 'yourFunction'); } Hi all I have been trying to do a query but I get Call to undefined function mysql_connect() What other way can I perform a query? Or do I need to get something enabled? Thank in advance Dave |