Jump to content

raydona

Members
  • Posts

    43
  • Joined

  • Last visited

Everything posted by raydona

  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.
  16. Hi, I have something like shown below: class Anon { $_dddd = null; ....... public function _construct() { $this->_dddd = DB::getInstance(); } $check = $this->_dddd->get(.......) ....... } class DB { private static $_instance = null; private $_pdo, $_query, $_error = false, $_results, $_count = 0; private function _construct() { try{ $dsn = sprintf( "mysql:host=%s;dbname=%s;", 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(); } return self::$_instance; } $_dddd is holding a SINGLETON object. When I do above I get following message: Fatal error: Call to a member function get() on a non-object Can anyone point out the mistake(s) in my code and how to rectify it. Will be very grateful.
  17. Hi, The array shown below is causing problems. I know this for sure because when I comment the array out the script runs. Is it: 'pswrd1'=>SHA1('$_POST['pswrd1']') inside the array causing the script not to run?? All help will be greatly appreciated. $register_data = array('username'=>$_POST['username'], 'first_name'=>$_POST['first_name'], 'last_name'=>$_POST['last_name'], 'address'=>$_POST['address'], 'postcode'=>$_POST['postcode'], 'country'=>$_POST['country'], 'e_mail'=>$_POST['e_mail'], 'pswrd1'=>SHA1('$_POST['pswrd1']'), 'phone_no'=>$_POST['phone_no']);
  18. Hi, Many thanks for the replies. Although I didn't include all the code, there is a lot of javascript in A.php to make the form appear stylish instead of the standard HTML inputs. That is why I wanted to keep the file separate from the php validation. I was wondering if I could write <form action="" method="post"> in A.php and include("A.php"); in B.php immediately below the php validation so that A.php appears immediately below the validation in B.php. But then how would I jump to input label?
  19. Hi, I have a form in file A.php. <?php <form name="A.php" action="B.php" method="post"> ...... <input type="text" name="name" id="name" /> .... <input type="text" name="email" id="email" /> .... ?> When the form is submitted php validation takes place on form B.php <?php if ( isset($_POST['submitted']) { if ($_POST[name]) { $name = $_POST[name]; } else { //what code goes here? } ...... ?> What I would like to happen in the else statement is that if name field is left blank user is automatically redirected to A.php, the name field is highlighted and a small error message that the name field was left empty appears. How can that be achieved? I would be very grateful for all help.
  20. Hi, I am having trouble styling the radio buttons and check boxes on this form. I want to reduce the gap between the label Sex and the radio buttons so that the buttons sit underneath 'T' in IT, also wish to reduce the gaps between the buttons and the words Male and Female. I wish to do the same for the check boxes. Would be very grateful for your help. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Temporary</title> <style type="text/css"> body { margin: 0; padding:0; } p { margin: 0 0 10px 0; padding:0; } form { font: 13px Georgia, "Times New Roman", Times, serif; background: #eee; margin: 20px; padding: 10px 20px; width: 330px; } form ol { list-style: none; margin: 0; padding: 0; } form li { padding: 6px; background: #e1e1e1; margin-bottom: 1px; } form label { float: left; width: 70px; text-align: right; margin-right: 7px; color: #0066CC; line-height: 23px; } form input { padding: 4px; font: 13px Georgia, "Times New Roman", Times, serif; border: 1px solid #999999; width: 200px; } form input:focus { border: 1px solid #666; background: #e3f1f1; } </style> </head> <body> <form> <p>Upload your educational and employment details:</p> <ol> <li> <label for="name">Name</label> <input type="text" name="name" id="name" /> </li> <li> <label for="email">Email</label> <input type="text" name="email" id="email" /> </li> <li> <label for="jobs">Job Sought</label> <select name="jobs"> <option value="clerical">Clerical</option> <option value="teaching">Teaching</option> <option value="computer" selected="selected">IT</option> <option value="driver">Driver</option> <option value="building">Construction</option> </select> </li> <li> <label for="sex">Sex</label> <input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex" value="female" /> Female </li> <li> <label for="education">Education</label> <input type="checkbox" name="education" value="school" /> Secondary School<br /> <input type="checkbox" name="education" value="college" /> Further Education College<br /> <input type="checkbox" name="education" value="university" /> Higher Education </li> </ol> </form> </body> </html>
  21. Hi, I want to place the following HTML statement inside an echo statement, i.e. in PHP I want to output an image that is also a link. <a href="#"><img src="Somefolder/animage.jpg" width="125" height="156" alt="some image" /></a> All ideas will be greatly appreciated.
  22. Hi, I got this symbol ► from MS Word Symbols table. I couldn't find a HTML code for the symbol. I am using it as a pointer in a vertical list. When I load the file to the web server the symbol is replaced by ? The server obviously doesn't recognize the symbol. I don't want to use an arrow icon because it appears in a square frame and it's hard to merge the background colour of the square frame with the background colour of the list, so that only the arrow appears and not the square background frame. Any ideas to get round this problem. I'll be very grateful.
  23. Hi, I have a 125 X 156 jpeg image with some text underneath in the right column of my home page and the same image and text in the right column of 47 other pages. When I update the image and text in my home page I don't want to do the same 47 other times. So I have placed the image and text in a separate file. I am guessing I have to insert preg_replace() function at the places where I want the updates to be made. My knowledge of PHP is not that great. So can anyone give me the exact function and parameters I have to use to replace the image and text. I would be very grateful.
  24. Hi, I'm new to PHP, so please bear with me. I've just downloaded an application. The following is part of PHP code in a config file that came with the application: // setting up the web root and server root for // this application $thisFile = str_replace('\\', '/', __FILE__); $docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile); $srvRoot = str_replace('library/config.php', '', $thisFile); define('WEB_ROOT', $webRoot); define('SRV_ROOT', $srvRoot); I don't know what are web root, server root or DOCUMENT_ROOT. Would it be possible to explain what this code is designed to do. Am I required to insert anything or make any alterations? I would be grateful for all help.
  25. Hi, I'm using phpMyAdmin (PHP Version 5.3.4) to create tables in a database. I'm a bit confused about Null and Default fields. I know Null is if someone doesn't want to insert a value. If this is ticked then a Default value has to be given (in which case it must be wrong to say: cat_id INTEGER NOT NULL DEFAULT 0,). For type INT would the Default be As defined: 0 and for VARCHAR As defined: ' ' or would one simply insert NULL? I'd be grateful for all help.
×
×
  • 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.