Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Content Count

    1084
  • Joined

  • Last visited

  • Days Won

    126

Everything posted by Antonio Conte

  1. Saw a large discussion about encryption of passwords some time ago. What you should do, is using a random string, and combine it with the password of the user. You then use SHA1 on this new string, and send it to the database. What's important, is that the same string is used when the user tries to log in. It's just a better way as it makes it harder to use rainbow tables and such. The discussion was were interesting as the debates included math (waaay over my head) on the matter. They concluded, that if you included a string into the password itself, it was impossible to be 100% sure of t
  2. How about making a drop down list for each brand? This is just me thinking. You wouldn't have to use javaScript then. The three level design is not that hard really. Larry is explaining how to this this in his PHP Advanced book. I will explain briefly. You need a database, or file system, that allows for this hierarchy. It's not really that hard. brands: (brand_id, brand_name) products: (product_id, product_name) three: (brand_id, product_id) SELECT a.brand_name as brand, b.product_name as product FROM brands as a, products as b INNER JOIN three as c on (a.brand_id = c.brand_i
  3. Hey, I'm working on a class to display information about football players. I have a little trouble understanding how I can make all players an individual objects though. Now the class is just printing out every player from the database as a string. Would it be possible to create every player as an object, and use the getters and setters I've created? Or is this not the correct use of objects and methods? I've seen in Java that you can pass an Object as a parameter for a method. Is this also possible in PHP? I don't really understand the point in instance variables as they are never use
  4. Yeah, I know. The most important is return values and examples of code. You don't need to read and understand it all. I had trouble figuring it out in the beginning too.
  5. - Escape your queries. mysqli_real_escape_string or prepared statements (if this is for a database) - type force (int) and use ctype_digit() on numbers. - Check length of string - Check if it contains values (!= null, !empty(), isset()) - Regex for email - Check out jQuery validate UI (it's great!) This will take you far. Good luck
  6. You still teach me things, Larry. I'm also doing a lot of Java at the moment, so I thought the two worked the same way. Paul. You should learn to read the PHP Manual. Look up mysqli_query() in there, and you see this "Return value". This is really important for understanding what to do with the code. It says that mysqli_query returns an RESULT OBJECT if the query is successfull, and FALSE if the query is not working. This gives you direction for what to do next. This means what you get from mysqli_query is not data, but a data object. That is a difference. Result object: I don't know
  7. Yes. Almost. There are steps you need to go through to get data from a database. 1. Connect to the database (This is the variabel $dbc) 2. Write a query. The variabel of your query is $q. 3. Execute the query. Almost there... (This is were you stop. 4. Get the info into an array so we can read and display it. You do this with mysqli_fetch_array(). I have switched names on your variables to better understand how they work. // This is query $query = "SELECT CONCAT (first_name, last_name) FROM users WHERE user_id = 22"; // The result of mysqli_query() $result
  8. What you need to understand is that we have different types of variables. - Local variables - Instance variables - Reference variables You $row[0] is a local variable. This is because it's declared inside the while loop. At the end, it dies. What this mean is that the variable does not exist after the while loop. It has no value, and the variable name is gone. $counter = 0; // available also after loops for ($i=0; $i<5; i++) { // $i is a local variable. It's value is available here, but not outside echo $i++; // add one as long as $i is less than 5 (5 times)
  9. <?php $query = "SELECT name, type, size, Content FROM Files WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error()); if ($result) { if (mysql_num_rows($result) == 1) { // if it num_rows = 1 } else { // if not } mysql_free_result($result); } else { // error } ?> First of, it seem you have one to many brackets in your code, after the $result if. Sorry. Just edited out some code before looking at it... From php.net: Mysql_query() For Select(...) mysql_query() returns a [b]resource on s
×
×
  • Create New...