Jump to content

xtremey_ytinasni

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

xtremey_ytinasni's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. However, another, much easier approach would be to extract the file name, and do a str replace and upper case the first letter of every word seperated by either a dot or an underscore.. so if your page name was my_page, it would display My Page, same with my.page, much easier, however doesn't let you choose really, would be based on the filename, but its not bad i think, much simpler
  2. As far as your wanting to set the page titles and having PHP do that.. Maybe including a comment block at the very top of each page, and having your template extract all the titles with fopen and a couple other tricks to grab that line with the comment for the title.. I mean its a bit complicated.. BUT it would ensure that if you add any pages, so long as you add that comment block specifying the title, it would automatically grab that..
  3. Basically, is this a good idea to use, or rather select only the fields you need for a certain reason. Say I have the fields: uid,uname,upass,usalt, and udisplayname. If a sneaky little .... somehow injected a query that is used for users that are logged in, wouldn't it be better to only have the relevant fields selected? ( In this case, uname,upass,and usalt should only be touched if adding a user, or having a user log in, because beyond that, why would you need something that's purpose is only for authenticating a user? ), or rather select all fields?. I've been wondering this for a while. So if I used my method ( select only relevant fields ), even if a sneaky little .... did inject sql to try and get a certain user's login information, it would not give them that info because those fields are NOT selected, as opposed to selecting all fields, and having that sneaky little .... get ahold of that users info.. Still even if I used uname and upass, they'd still have to figure out that I'm using a unique salt for each user, and that even if 2 users have the same password, theyd need to do seperate rainbow tables for each password.
  4. My reason for creating this simple little class is because it just makes it kind of easier... I'm also creating a Validation class and will be posting it shortly for review...
  5. Would this be a decent class to use, or is there anything I should add,edit, or remove? <?php /** * MySQL Database Class * * @author: Dillion DeWitt * @copyright: Dillion DeWitt (c), 2012. */ class DB { var $link; var $host; var $user; var $password; var $database; var $query; var $result; var $debug=false; function connect($host,$user,$pass,$database=false,$persistent=false){ //Assign values to class variables. $this->host = $host; $this->user = $user; $this->password = $pass; if( $persistent ){ $this->link = mysql_pconnect($host,$user,$pass); } else { $this->link = mysql_connect($host,$user,$pass); } if( $database ){ $this->database = $database; mysql_select_db($database,$this->link); } } function isConnected(){ if(mysql_ping($this-link) === true){ $msg = 'Connected.'; } else { $msg = 'Disconnected.'; } return $msg; } function query($sql){ $this->query = $sql; $this->result = mysql_query($sql, $this->link) or $this->Error(); } function num_rows($result){ $result = $this->result; return mysql_num_rows($result); } function get_single($result){ $result = $this->result; return mysql_fetch_row($result); } function get_rows($result){ $result = $this->result; return mysql_fetch_assoc($result); } function Error(){ if($this->debug){ echo mysql_errno().': '.mysql_error(); exit; } else { echo 'An error has occured.'; exit; } } } ?>
  6. Is it a good idea to reuse say a database file someone else made, or should you try to make your own?
  7. What are the best methods/practices for beginners/novices to learn? Hopefully this will help a lot of people, so please if you don't mind, post your methods/practices that have worked for you, or generally accepted methods/practices.
  8. Depends on what you want to do. Are you trying to get the values in SALES for any employees with a matched ID?
  9. The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). ( from w3schools.org). So basically, when left joining, you would have the LEFT table's (in this instance "id") column JOIN with with the right table's column, thus LEFT JOIN Well, im just talkin from what it sounds like, and thats always the way i've used it and it works fine so dont see a problem. I think it might help you to know that you do not need to concatenate pieces of a string together like that just because you want to break the SQL statement up into seperate lines. $sql_emp = 'SELECT a.`id`,a.`name`,a.`surname`,b.`points` FROM `table_name` a LEFT JOIN `table_name` b ON a.`id`=b.`id`'; However, am i correct in assuming that syntax would work? I didn't test it, just used knowledge of writing SQL.
  10. Yeh... like I said I'm still learning as well. I knew i didnt have to concatenate. Don't know why i was though :L Well I learned
  11. The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). ( from w3schools.org). So basically, when left joining, you would have the LEFT table's (in this instance "id") column JOIN with with the right table's column, thus LEFT JOIN Well, im just talkin from what it sounds like, and thats always the way i've used it and it works fine so dont see a problem.
  12. $sql_emp = 'SELECT a.`id`,a.`name`,a.`surname`,b.`points` '. 'FROM `table_name` a '. 'LEFT JOIN `table_name` b '. 'ON a.`id`=b.`id`'; That should work. Honestly you don't have to break it by lines, but I find that this makes it much easier to edit the query, and much easier to read. Just a preference, but looks much cleaner to me. So anyway, you should now be able to use that sql for query and grab the data with thier respective column names.
  13. I have no idea how to edit a post on this forum, but anyway, I just did a test on the little thing I wrote for you... Short: It works. I'm sure it could be advanced, but you asked for it, and I gave you the solution ( hopefully I understood ). EDIT: Wait... It's not displaying multiple beaches. One sec
  14. The only problem for me to not be able to do this, is that you have a column in each table with the name (name). Thus, with LEFT JOIN, i don't think you could seperate the values for each one, or maybe I'm wrong... but if you changed it to say like: cName,rName,srName,and bName, it'd look something around this ( for the query, the html I'm not good with unordered lists, so shouldn't be too hard to fix any mistake ): <?php //Your connection stuff here $mysql = 'SELECT c.`idCountry`,c.`cName`,r.`idRegion`,r.`idCountry`,r.`rName`,sr.`idSubRegion`,sr.`idRegion`,sr.`srName`,b.`idBeach`,b.`idSubRegion`,b.`bName` '. 'FROM `country` c '. 'LEFT JOIN `region` r '. 'ON c.`idCountry`=r.`idCountry` '. 'LEFT JOIN `subregions` sr '. 'ON r.`idRegion`=sr.`idRegion` '. 'LEFT JOIN `beach` b '. 'ON sr.`idSubRegion`=b.`idSubRegion` '. 'GROUP BY c.`idCountry` '; //Multiple Left joins. Feel free to add an ORDER BY, if you'd like. $q = mysql_query($mysql,$conn_id); while($data = mysql_fetch_assoc($q)){ echo '<ul>'.$data['cName']; echo '<li><ul>'.$data['rName']; echo '<li><ul>'.$data['srName']; echo '<li><ul>'.$data['bName']; echo '</ul></li></ul></li></ul></li></ul>'; } ?> NOTE: This has not been tested, and I've never worked with more than 2 left joins, but I really do hope it works for you. The only thing I am worried about this is that it may not group everything correctly, but it should... If it works, awesome
  15. I am currently testing a small hash idea, for say database encryption for passwords. Basically what I want to know is if this is a good or not the best method for encryption... <?php $us_password = 'drowssap'; // User-Submitted Password; $salt = '))!&8d*34d763!(('; //The salt $dbs_password = '3750221c513902ff76f4ec7ffed5fa4385d2599d'; // Sha1 hash for "drowssap"+Salt; if($us_password == sha1($us_password.$salt)){ //Some other code for success here } else { //Failure code here } ?> So basically, this is an abstract example of what I'm doing... Is it any good, or what could be improved? I've also used DB-Stored salts unique to each user, so even if someone used rainbow tables ( even after failure on my part for letting them get the hash... ), and multiple users had the same password, they would only crack one, rather than all of them, since the hashes would be different due to the different salts.
×
×
  • 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.