Jump to content

Frank_b

Members
  • Posts

    155
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Frank_b

  1. I understand now that you talk about clients or customers and i talked about users. Not so much difference... The numbers are just random codes. I like to keep some space between the numbers for in case that you want to insert another level later. The problem that i see in your code is that the words low, medium and hig appear everywhere in your code. Would you like to change something later then you will have search all your codefiles and replace them.
  2. Keep the variables inside your classes private like my example with the class User.
  3. another hint: i see everywhere 'mid' 'high' etc. This is too much 'green' or constants. Change that like this: // configuration: define('USERLEVEL_LOW', ; define('USERLEVEL_MEDIUM', 32); define('USERLEVEL_HIGH', 128); // In the rest of you code: class ClientLvl { private $client_lvl = USERLEVEL_HIGH; }
  4. your post is too long to read it completely. starting with classes is not so easy. I guess you did read some tutorials. First of all: give a class only one responsibility! as soon you start to say "this class do this AND do that" you are on the wrong way. Second: a Class use other classes! (Normaly we don't speak about classes but about objects) class User { private $username; // more code } class Authenticate { public function Login(User $user) { echo 'Hello ' . $user->getName(); } } Third: Functions inside classes that we call methods can share data inside that class class User { private $username; public function getUsername() { return $this->username; } public function setUsername($username) { $this->username = $username; } }
  5. to get a better picture of the data that is available after a selectquery use the print_r function: $row = $user->fetch(PDO::FETCH_ASSOC); echo '<pre>'; print_r($row);
  6. It's a bit hard to understand what you want to reach.. What are you try to make? For what purpose is shoutBoxBan in the users table? Are that the administrators? Who do you want to give unBan future? Only administrators? SELECT s.id, s.message, u.id as uid, u.name, u.shoutBoxBan FROM shoutbox s LEFT JOIN users u ON s.user_id=u.id if($usersRow['shoutBoxBan'] == 'yes'){ // administrator }
  7. appologizes there was a typo :-) <?php function buildOptions($tablename, $columnname, $selectedId = 0) { $sql = 'SELECT id, '.$columnname.' FROM '.$tablename; $html = ''; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) // use mysql_fetch_assoc! { $selected = ''; if($row['id'] == $selectedId) $selected = ' selected="selected"'; $html .= '<option'.$selected.' value= "' . $row['id']. '">' . $row[$columnname] . '</option>' . "\n"; } return $html; } $userId = 0; if($_SERVER['REQUEST_METHOD'] == 'POST') { $userId = $_POST['user']; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Example</title> </head> <body> <form action="" method="post"> <select name="user"> <?php echo buildOptions('users', 'name', $userId); ?> </select> </form> </body> </html>
  8. I only see <form></form>. Where are the input fields? the index for the $_POST array has to be the same as the name attribute inside your input fields and are case sensitive. eg: <input type="text" name="email" /> <==> $_POST['email'] And to be honest: your code is a nightmare :-)
  9. <?php function buildOptions($tablename, $columnname, $selectedId = 0) { $sql = 'SELECT id, '.$columnnmame.' FROM '.$tablename; $html = ''; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) // use mysql_fetch_assoc! { $selected = ''; if($row['id'] == $selectedId) $selected = ' selected="selected"'; $html .= '<option'.$selected.' value= "' . $row['id']. '">' . $row[$columnnmame] . '</option>' . "\n"; } return $html; } $userId = 0; if($_SERVER['REQUEST_METHOD'] == 'POST') { $userId = $_POST['user']; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Example</title> </head> <body> <form action="" method="post"> <select name="user"> <?php echo buildOptions('users', 'name', $userId); ?> </select> </form> </body> </html>
  10. what do you get if you change the query to: $result = mysql_query('SELECT COUNT(*) AS id_count FROM MyTable)'; What is the database storage type? (e.g. InnoDB or MyISAM)
  11. mysql_ functions are deprecated! it says that your query have failed. to check it out what goes wrong you should add error reporting: $query = mysql_query ("SELECT COUNT (user_id) FROM user WHERE username = '$username'"); $result = mysql_result($query); if(!$result) echo mysql_error($link);
  12. Okay there is a check.. in this case that is possible but with many other relations between tables there is no check. So the standard is to use a autoincrement (and unique) id. And why not follow this standard with the users table?
  13. Hi timtam, When you run setup.php it will create the the json file in the /private directory. after setup you should have this: |----[private] | | | |---- .htaccess | |---- users.json | |---- users.php | | |---- index.php |---- login.php |---- logout.php |---- members.php |---- setup.php
  14. Ch0cu3r is right. And give functions always reliable names so that you immediately understand what the function does.
  15. In addition to my example tables: With a JOIN you can retrieve all the information you need: SELECT s.id, s.message, u.id as uid, u.name FROM shoutbox s LEFT JOIN users u ON s.user_id=u.id after this you can also add a WHERE, ORDER BY or LIMIT. Notice that i did not use a * in the SELECT but instead a list of columnnames . because both tables have a column 'id' i gave an alias for the user-id which i called uid. The result of the query will look like this: id | message | uid | name ------------------------------- 26 | Some text | 1 | Frank 27 | Another text | 2 | Jacob
  16. What if you have two users with exactly the same name? Or what if a moderator creates two accounts? One account as a normal user and one for moderating?
  17. Am i right that you store usernames in the shoutbox table instead of the user id? You shouldn't do that. Yes you can retrieve all the required information in one time lets give an example: Table users: id: INT primary key, auto increment name: VARCHAR 255 email: VARCHAR 255 ... Table shoutbox: id: INT primary key, auto increment user_id INT foreign key (also called Index) message: longtext ...
  18. I made a begin on a manner how you could do this. You should only use it for learning. Write your own code! Dig everything out until you understand how it works! unpack the zip in the document root or a higher directory on your webserver. Then browse to the setup.php file if you don't get errors then setup ended successfully. You have two users: Frank with password 1234 Newbee with password 0000 No sessions, cookies or database is used. Users are stored in a file in a directory with the name private which will not be accessible from the web. The file format is JSON plaintext. I've added comments in the code. For any questions you can leave a message here. Success. login.zip
  19. Hi mr 'Advanced Member', i am just willing to help somebody and i am sorry if you don't like it. And maybe the topic starter will still like to communicate on this forum. :-)
  20. Ok, "No database or cookies are required". "All data should be passed from form to form" Tells me that it is not forbidden to use a database OR cookies :-) What hurts me is that they want us to pass all data from form to form which is a very big security hole. It means that we have to include a query string on every link that we write to help us remember who is logged in. To make it a bit more secure we use the password and username scrambled into the query string. eg: http://mysite.org/profile.php?sid=hfqe0weyr40faqew0runqrvfda I think i should make a login WITH database OR file storage. And i should use all the guidlines for the sign-up and profile pages. I asume that you know how to maken a form in HTML. Start with that part: I think this is what you have to make first: - an index page with links to the other pages like the profile page - a login form - a profile page (later it will be after the login) -a edit-your-profile page (later it will be after the login) - a add-user page (later it will be after the login) i ll send you a private message later.
  21. Looks like your script cannot establish connection with your database server. Did you setup the servername, username, password and databasename correctly in the config of your system?
  22. a login without sessions is not really posible. Unless you want to use it for only one page. You don't have to use cookies yourself but sessions will store a cookie on the clients computer. a registration page means that you will have to deal with a dynamic number of users with all different names an emailaddresses etc.. You will need to store that data somewhere. A database is most common but store your data into a file is also possible.
×
×
  • 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.