ManiacDan
Staff Alumni-
Posts
2,604 -
Joined
-
Last visited
-
Days Won
10
Everything posted by ManiacDan
-
Warning: Invalid argument supplied for foreach() in
ManiacDan replied to Eksotik's topic in Frameworks
Unfortunately that's the problem with tutorials like this. $this is an object-specific variable. It can ONLY exist inside a function which is inside an object. You don't know what I'm talking about. This is because what you're looking at here is a snippet of code that's designed to be sucked into an object function without your knowledge. Nobody has any chance of figuring out what your code is doing until you post the contents of the object, if you even know where that is. My personal recommendation is to not dive into a framework until you've learned the basics of how PHP works on your own. -Dan -
Need a generic update function to update a mysql table
ManiacDan replied to colap's topic in PHP Coding Help
You're going to have to be more specific. You can write a function that will accept an associative array and will construct an update statement. However, you won't be able to write it to have intelligence about the data type for the queries without doing a SHOW CREATE TABLE and parsing it yourself. -Dan -
can someone please for the life of me/ Show me how to write this???/
ManiacDan replied to Shizzx's topic in PHP Coding Help
Well...what are you having trouble with? Page 41 of that book includes the instructions for arrays, use an array for question 1. -
Warning: Invalid argument supplied for foreach() in
ManiacDan replied to Eksotik's topic in Frameworks
If you're not fetching data, it won't be available. Turn on error reporting by putting this line at the top of your script: error_reporting(E_ALL); Using a framework generally isn't the best way to get started with a programming language, because you're not seeing all the "behind the scenes" things. -Dan -
can someone please for the life of me/ Show me how to write this???/
ManiacDan replied to Shizzx's topic in PHP Coding Help
The first one requires much more background information. Are you ready for arrays? Objects? Databases? The second one is very very easy. So easy, that the only hints we can give you is to do it for you. Echo the numbers, use the given operators to perform the calculations. -Dan -
Warning: Invalid argument supplied for foreach() in
ManiacDan replied to Eksotik's topic in Frameworks
That means $this->albums is not an array. Your code assumes that it is. This code is...weird. What kind of tutorial are you following? Did you do all the other steps up to this point? Is this a zend framework tutorial? -Dan -
There isn't much we can do other than to recommend the books and tutorials that helped us. I read "Web Database Programming in PHP and MySQL" (by O'Reilly) cover to cover, and I also read through the entire MySQL 5 manual, also cover to cover. Learning by doing is probably much easier for a dyslexic, but I can't say that for sure. -Dan
-
Can't post in phpfreaks.com/forums
ManiacDan replied to colap's topic in PHPFreaks.com Website Feedback
Yes, that's because your posts are required to be moderated before they can be posted. I've approved your most recent post on SQL Joins. -Dan -
how do securely store username and password in cookies ?
ManiacDan replied to jasonc's topic in PHP Coding Help
Auto-login cookies are generally created using a hash of four things: 1) Something they know that you don't know (password) 2) Something you know that they don't know (auto-generated hash stored in their user table, the microtime of their signup time, etc) 3) Something unique to their machine (IP) 4) A fixed salt that no user knows. Hash all those things, and store them in the DB along with their username or UserID. When they come back to the site, load the data for their user, and compare the generated hash on the server with the hash stored on their machine. If it matches, log them in. If it doesn't match, kill the cookie and kick them to the login page. -Dan -
how do securely store username and password in cookies ?
ManiacDan replied to jasonc's topic in PHP Coding Help
Never store username and password in a cookie. If you must use a "remember me" cookie, do that, but don't actually store their password on their machine. Also, sessions rely on cookies, so you've been breaking your rule all along. -Dan -
Oh, so in addition to "keeping score" for the game itself, you're also "scoring" the teams in league play. Those should be kept in a separate table (or calculated on the fly). Don't give the team the 3 points until after the game is finished with. -Dan
-
Wait...in what country do soccer games score in 3-point intervals? Why are you claiming your queries will update the wrong way...or something. Show the queries you're running. Your WHERE clause should be identifying these games based on a unique identifier (either an auto-increment ID in the database or by team/date), not by score. -Dan
-
How to take the first letter and insert it in another field
ManiacDan replied to hoverinc's topic in MySQL Help
There's nothing else we can tell you aside from writing the query for you. UPDATE someTable SET field2 = LEFT(field1, 1); Also, there's no reason to ever do this, you're duplicating data and you'll only make it hard on yourself. -Dan -
Whichever ones are in the Zend_Controller_Action_interface constructor. Look into inheritance in OOP PHP. -Dan
-
Zend framework doesn't have a problem with constructors, they're critical to OOP development. What makes you think it has a problem?
-
James is right. You can also look into instances singleton classes, so you can just say DB_Object::getInstance() every time, which always returns the same memory location. -Dan
-
This is what PHP is doing: echo 'a'.false ? 'b' : 'c'; //becomes echo strval('a'.false) ? 'b' : 'c'; //becomes if ( strval('a' . false) == true ) { echo 'b'; } else { echo 'c'; } -Dan
-
Right...there's 1024 kb in a mb. Division is built into every language.
-
With comments: <?php class Mysql { public function __construct() { //this doesn't go anywhere. Look into PHP scope. $mysqli = new mysqli( 'localhost', 'root', '', 'login' ); } } class Query extends Mysql { public function loginQuery() { //again, this does nothing and goes nowhere. $query = "SELECT gebruikerid FROM gebruikers WHERE gebruikersnaam = 'wouter' AND wachtwoord = 'test'"; } } class User { public function __construct() { $this->mysql = new Mysql(); } public function login() { //this function doesn't exist anywhere on any class, neither does $query $this->mysql->query( $query ); } } ?> -Dan
-
Yeah...that was all kinds of wrong. class User { public function __construct() { $this->db = new Database(); } public function login() { $this->db->query( $yourLoginQuery ); } }
-
print_r($something,true) instead of print_r($something). The second argument, when true, returns the item as a string so it can be used in an echo like this. Otherwise, the output is weird. -Dan
-
Look into Snoopy(), it's a PHP class that masquerades as a browser, including proper cookie handling. -Dan
-
You need to make the database connection a member variable of the user class: class User { public function __construct() { $this->db = new Database(); $this->db->login(); } } Also: the way I've described here is inefficient, look into the singleton pattern and instanced classes in PHP. -Dan
-
need help with syntax error for form process
ManiacDan replied to webguync's topic in PHP Coding Help
There are no syntax errors in the code you posted. Are you sure you're looking at the right file? There's a filename in the error message, is that the one you're looking at? -Dan -
Make them full text if you want to search them. If you want to simply SELECT the ones that aren't fulltext, fulltext matching works on the WHERE condition. You can easily say: SELECT id, name FROM products WHERE MATCH(description) AGAINST('dog') -Dan