Jump to content

Andy-H

Members
  • Posts

    2,000
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Andy-H

  1. Andy-H

    Class

    This class works fine; I was just wondering if I am using it right and if there is any way to operate on multiple queries with one instance of the class. ??? <?php class db { var $host; var $user; var $pass; var $DB; function db($host = 'localhost', $user = '*******', $pass = '*******', $DB = '*******') { $conn = mysql_connect($host, $user, $pass); $db = mysql_select_db($DB, $conn); } function query($str) { $this->query = mysql_query($str)or die('Query failed on line ' . __LINE__); } function num() { return mysql_num_rows($this->query); } function fetch($type = 'row') { return mysql_fetch_row($this->query); } } ?>
  2. $db = new db_works; $db->connect(); $query = "SELECT blah1, blah2 FROM tblBlah ORDER BY timesUsed DESC LIMIT 10"; $result = $db->query($query); Is that how you would use it?
  3. Thanks, hopefully editing that will get me the basic understandings. If I get this right I'll post the code back later for anyone to critisize constructively or otherwise lol
  4. ahhh, thanks, Ill look into it
  5. From the tutorials I have read so far I got this far: <?php Class db { function db() { $this->host = 'localhost'; $this->user = '*****'; $this->pass = '*****'; $this->data = '*****'; $conn = dbConnection(); } function dbConnection { $link = mysql_connect($this->host, $this->user, $this->pass)or die('Unable to establish link to db.'); $conn = mysql_select_db($this->data, $link); } lol I assumes it was completely wrong and decided tutorials arent my style. I just perfer to edit the code, read the errors and fix them. Thats how I learned procedural anyway lol
  6. What does it do? lol
  7. Ok, I dont actually have any code right now, I have been looking into OO PHP to build a MySQL class to handle connections, querys, fetching data etc. I have read a few tutorials with no success into understanding how to so this due to the tutorials all being written in shroom season and comparing OO PHP to magic boes and stuff :S DOes anyone know of a simple OOP database handeling script that I can pick apart abnd try to learn from? Thanks for replies/help.
  8. *link removed* Jus found that, loads of examples from web programming books on O'Reilly =P
  9. You got error reporting set to e_all and display errors on?
  10. if(!$username){ $errors[] = "You did not supply a username!"; } if(!$password){ // was if !$username $errors[] = "You did not supply a password!"; }
  11. $query = "SELECT wordUsed FROM keyWords ORDER BY timesUsed DESC LIMIT 10"; $result = mysql_query($query); while ($row = mysql_fetch_row($result)){ code; }
  12. basically I want to retrieve 10 keywords from my database based on which ones occur most. The db layout is: --keyWords-- id (int)11 auto_inc primary_key wordUsed (text). timesUsed (int)11 ------ I think it has something to do with the max function but am not sure how to use it in the `Where` clause Any help appreciated.
  13. No, javascript can be disabled by the user and therefor isn't consistant in any browser. Use something like PHP and make a little class or function to display it at the top of the page each time it loads, then when they do whatever update the status.
  14. orders.txt is chmodded to 666?
  15. $query = mysql_query("SELECT * FROM users WHERE pin = '' ")or die("Error"); $n = 0; while ($fetch = mysql_fetch_object($query) && $n < 1000){ $pin = rand(1000000,9999999); $pin = md5($pin); $q = "SELECT * FROM users WHERE pin = '$pin' LIMIT 1"; $r = mysql_query($q)or die('Error (2)'); $num = mysql_num_rows($r); if ($num == 0){ mysql_query("UPDATE users SET pin = '$pin' WHERE username = '$fetch->username' LIMIT 1"); $n++; } }
  16. http://unix.com.ua/orelly There is alot of good books for learning programming there, I think they are all quite old but will get you on your feet.
  17. Andy-H

    Echo

    Why are you usinf stripslashes after the fwrite() function?
  18. <?php $tmp_last = $arr[0]; $tmp_first = $arr[1]; $link = mysql_connect("-----", "-----", "-----", "----"); if ( get_magic_quotes_gpc() == 1 ): stripslashes($tmp_last); stripslashes($tmp_first); Endif; $tmp_last = mysql_real_escape_string($tmp_last, $link); $tmp_first = mysql_real_escape_string($tmp_first, $link); ---- $nsql = '(`ruat_tsa_last_name` LIKE CONVERT(_utf8 \'%'.$tmp_last.'%\' USING latin1) COLLATE latin1_swedish_ci '; $sql .=$nsql; $nsql = ' AND `ruat_tsa_first_name` LIKE CONVERT(_utf8 \'%'.$tmp_first.'%\' USING latin1) COLLATE latin1_swedish_ci ) '; $sql .= $nsql; ?> I'm out of my depth here but from reading the topic this seems to be what people have suggested...
  19. and mysql_fetch_object(); to return the results as an object. http://php.net/mysql_fetch_object e.g. <?php $auth = mysql_fetch_object($find); $username = $auth->username; ?>
  20. $find = mysql_query("SELECT `username`,`password`,`active` FROM users WHERE `username` = '$username' AND `password` = '$password'"); if (!$find) { die('Could not query1:' . mysql_error());} $auth = mysql_fetch_array($find, MYSQL_ASSOC); print_r($auth);
  21. Just encrypt the password with md5() when you store it in the database and md5() the postdata and it will me more secure and case sensitive.
  22. 3528 Sorry was at college at the time and my pc broke when I got home It was just the slow host, sorry about wasting time
  23. I need that to filter the image format tho.
×
×
  • 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.