Jump to content

raydona

Members
  • Posts

    43
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

raydona's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi, I'm trying to load an application on unix server but when it does system check I keep on getting following error message and application will not load. Your PHP Version is 5.6.22, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider. As suggested by my hosting provider I've created php.ini file and put always_populate_raw_post_data = -1 into file and placed in public_html folder. But it is not solving problem. Any suggestion as to what I should do to solve problem? I'm completely new to all this. All help will be greatly appreciated.
  2. Hello, I want to install a new application on my unix x86_64 (virtual) server. The server has MySQL Version 5.5.49 but the application requires MySQL 5.6 or upwards. I want to update MySQL on my server. I have seen an article where it says: Replace the MySQL version from 5.4.9 with 5.6 in /var/cpanel/cpanel.config file #vi /var/cpanel/cpanel.configand then, change -------"mysql-version=5.4.9" to "mysql-version=5.6". Neither the directory /var/cpanel/cpanel.config nor the file cpanel.config exist on my server. (Also there is no directory \usr.) Do I have to create these manually? If so what do I enter in the .config file? Is there an easier way of upgrading? There are no buttons on my server for upgrading MySql easily as there is for PHP.
  3. Hi, Thanks for your help. Before I try out some of your suggestions can I ask does it make a difference if the collation of the database is "latin1_swedish_ci" while the collation of the table is "utf8_general_ci"? Also I have just discovered that my program works on a remote server with operating system linux but not on a remote server using windows operating system, my program is intended for latter. I still get: The error is now showing only one array. I don't know why it showed two previously?? This problem is beyond me!!
  4. Sorry, in my confusion I did the wrong thing and should have written: public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { print_r($this->_query->errorInfo()); $this->_error = true; } } return $this; } The message I get is: Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'postcode' in 'field list' ) Problem creating an account! Previously it said "Unknown column 'address' in 'field list'". Now it's saying "Unknown column 'postcode' in 'field list' ". There is nothing wrong with the fields in the database. I've checked them a hundred times. There is something wrong with the database. Could this be a problem with the server rather than my coding? Please help?
  5. Hello, Many thanks for your help. I've checked, $sql does contain a valid INSERT sentence. It's both a comparison and an assignment. Whatever is returned by prepare() is assigned to _query and this is tested I've tried the following debugging. public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); print_r($this->_query->errorInfo()); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } The message I get is: I don't how to interpret this error message. Could you please help?
  6. Hi, My program works on WAMP (PHP Version 5.5.12) running on my machine. However, the same program will not run on remote server (PHP Version 5.4.32). Basically, I'm trying to insert values obtained from a form into a database. I've checked and rechecked the table I'm inserting into and I can't find anything wrong with it. The trouble is it's hard to debug a PHP program. Unlike, say, C++ which requires a compiler, you can trace the program line by line to look for errors. That's not possible with PHP and makes it so much harder to look for faults. The relevant functions used to send data to database are shown below. insert() is returning false every time and I can't understand why! I wonder if anyone can suggest where things might be going wrong. I would be very grateful. public function insert($table, $fields = array()) { if(count($fields)) //true if $fields holds data { $keys = array_keys($fields); $values = ''; //to put inside query $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO {$table} (`".implode('`, `', $keys) . "`) VALUES({$values})"; if(!$this->query($sql, $fields)->error()) { return true; } } return false; } public function query($sql, $darams = array()) { $this->_error = false; //reset error if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } public function error() { return $this->_error; } public function count() { return $this->_count; }
  7. Hello, I have following function find() in class User: public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { $this->_data = $data->first(); return true; } } return false; } When line "if($data->count())" is encountered I get following message: Fatal Error: Call to a member function count() on a non-object $data should hold a DB object but doesn't. class User { private $_db; private $_data; private $_sessionName; private $_isLoggedIn; public function __construct($user = null) { $this->_db = DB::getInstance(); .................. Class DB is shown below: class DB { private static $_instance = null; private $_pdo, //PDO object $_query, //last query executed $_error = false, $_results, //store results set of a query $_count = 0; private function __construct() { try { $dsn = sprintf( "mysql:host='';dbname='';", Config::get('mysql/host'), Config::get('mysql/database') ); $this->_pdo = new PDO( $dsn, Config::get('mysql/username'), Config::get('mysql/password')); } catch(PDOException $excp) { die($excp->getMessage()); } } public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; } public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } public function action($action, $table, $where = array()) { if(count($where) === 3) //field, operator, value { $operators = array('=', '>', '<', '>=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; if(!$this->query($sql, array($value))->error()) { return $this; //no error return $this } } } return false; } public function get($table, $where) { return $this->action('SELECT *', $table, $where); } public function error() { return $this->_error; } public function count() { return $this->_count; } public function results() { return $this->_results; } public function first() { return $this->results()[0]; } I have debugged the program as far as I could. The problem lies in the following function: public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } When line "if($this->_query->execute())" is encountered program does not execute and null is returned. I have taken bits of this function from the internet and have put it together with my code. That's where the problem lies. Is there any way query(), or if need be any other function, can be altered, within context of class DB, so that query() returns an object of class DB which can be used in find()? Will be very grateful for all assistance.
  8. Hi, Many thanks for the replies. I still cannot resolve the problem. I have now included all of the relevant code. The code relating to PDO I got off the internet with which I am not fully conversant. In class User: public function find($user = null) { if($user) //if username is passed, not null { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { $this->_data = $data->first(); return true; } } return false; } In class DB: class DB { private static $_instance = null; private $_pdo, $_query, $_error = false, $_results, $_count = 0; private function __construct() { try { $dsn = sprintf( "mysql:host='';dbname='';", Config::get('mysql/host'), Config::get('mysql/database') ); $this->_pdo = new PDO( $dsn, Config::get('mysql/username'), Config::get('mysql/password')); } catch(PDOException $excp) { die($excp->getMessage()); } } public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; } public function get($table, $where) { return $this->action('SELECT*', $table, $where); } public function action($action, $table, $where = array()) { if(count($where) === 3) //field, operator, value { $operators = array('=', '>', '<', '>=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; if(!$this->query($sql, array($value))->error()) { return $this; //if not an error return $this } } } return false; //outside of everything return false } public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; }
  9. Hi, I have the following class: class User { private $_db; public function __construct($user = null) { $this->_db = DB::getInstance(); ....... } public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { ......... return true; } } return false; } In class DB I have: public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; } public function get() in class DB, after processing, returns $this, the single instance of class DB, this is assigned to $data which is then used to invoke public function count(), a member function of class DB. I am getting the following error: Fatal error: Call to a member function count() on a non-object. I would be very grateful if someone can point out my mistake.
  10. Hi, The code for setting the $token variable is: public static function generate() { return Session::put('token'), md5(uniqid())); } which is basically md5(uniqid()). Immediately after form is submitted I get: string '9a0453403ae941b6ae5744882dce0f08' (length=41) which suggests non-printing characters are inserted when $token is created.
  11. Hi, I have included the following code that is relevant to the problem described above: <?php class Token { public static function generate() { return Session::put('token'), md5(uniqid())); } public static function check($token) { $tokenName = 'token'; if(Session::exists($tokenName) && $token === Session::get($tokenName)) { Session::delete($tokenName); return true; } return false; } } /////////////////////////////////////////////////////////////// class Session { public static function exists($name) { return (isset($_SESSION[$name])) ? true : false; } public static function put($name, $value) { return $_SESSION[$name] = $value; } public static function get($name) { return $_SESSION[$name]; } public static function delete($name) { if(self::exists($name)) { unset($_SESSION[$name]); } } /////////////////////////////////////////////////////////////// class Input { public static function get($item) { if(isset($_POST[$item])) { return $_POST[$item]; } return ''; } } ////////////////////////////////////////////////////////////// if(isset($_POST['username']) && isset($_POST['password'])) { if(Token::check(Input::get('token'))) { $validate = new Validate(); $validation = ................; if($validation->passed()) { $user = new User(); $login = $user->login(Input::get('username'), Input::get('password')); if($login) { echo 'Success'; Redirect::to('index.php'); } else { echo 'Sorry, login failed!'; } } //validation passed else { foreach($validation->errors() as $error) { echo $error, '<br>'; } echo "<script> setTimeout(\"location.href = 'index.php';\",30000); </script>"; } } } ?> <form action="" method="POST"> <P> <label for="username">Username</label> <input type="text" name="username" id="username" autocomplete="off"> </P> <P> <label for="password">Password</label> <input type="password" name="password" id="password" autocomplete="off"> </P> <P> <input type="hidden" name="token" value="<?php echo Token::generate(); ?>"> <input type="submit" value="LOG IN"> </P> </form> This is what 'view source' in the browser of the var_dump() output shows: <pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'e62862d9f9ce6cd41fc7873c53683108'</font> <i>(length=41)</i> </pre><br><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'e62862d9f9ce6cd41fc7873c53683108'</font> <i>(length=32)</i> </pre><br> <form action="" method="POST"> <P> <label for="username">Username</label> <input type="text" name="username" id="username" autocomplete="off"> </P> <P> <label for="password">Password</label> <input type="password" name="password" id="password" autocomplete="off"> </P> <P> <input type="hidden" name="token" value="695d40eec4673a3b8a36493c67cdfbd4"> <input type="submit" value="LOG IN"> </P> </form>
  12. Hello, Many thanks for the reply. I used var_dump() on both values and the following is obtained: string 'be33cfc1f0eed02e8176d7281975b05e' (length=41) string 'be33cfc1f0eed02e8176d7281975b05e' (length=32) If there are any extra white-space/non-printing characters I don't know how to locate and remove them. I've used trim() but it's not solving the problem. Could you please suggest a solution.
  13. Hi, I asked a question about Tokens earlier. After debugging I've found the reason as to why my program isn't working. It's related to this statement: if($token == $_SESSION['token']) { ........; return true; }$token is generated in form using md5(uniqid()). When I echo both $token and $_SESSION['token'] before the if statement they both turn out to be the same. Yet for some reason the if statement is not being satisfied and is not returning true as it's supposed to do. (I've tried $token === $_SESSION['token'] as well.) I don't know if some kind of type casting or other is required for the conditional statement to work. Would be grateful for any suggestions.
  14. Hi, Say I have the situation shown below: <form action="" method="POST"> <P> <label for="username">Username</label> <input type="text" name="username" id="username" autocomplete="off"> </P> <P> <label for="password">Password</label> <input type="password" name="password" id="password" autocomplete="off"> </P> <P> <input type="hidden" name="token" value="<?php echo md5(sha1($salt.$ip).sha1($salt.$formName)) ?>" /> <input type="submit" value="LOG IN"> </P> </form> When form is submitted a hash is generated for the line: value="<?php echo md5(sha1($salt.$ip).sha1($salt.$formName)) ?>" However, it is found username or password is incorrect and the form has to be resubmitted with correct username or password. When form is submitted for a second time is a new hash generated in the line: value="<?php echo md5(sha1($salt.$ip).sha1($salt.$formName)) ?>" which is likely to be different from the first one?????
  15. Hello, I have the situation shown below in the code: if(//condition is met) { $val = new Val(); $valon = $val->check($_POST, array(.........)); } if($valon->passes()) { $use = new Use(); ........ } //check() and passes() both belong to class Val public function check($source, $items = array()) { ...................... return $this; } I get the following warning and error: Notice: Undefined variable: valon and Fatal error: Call to a member function passes() on a non-object I can't see anything wrong with the code. check() returns an object of class Val which is assigned to $valon, $valon then calls a member function of class Val. Could you please help. Please let me know whether to include further code.
×
×
  • 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.