Jump to content
Larry Ullman's Book Forums

Matt

Members
  • Posts

    173
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Matt

  1. Ah, I missed that when I was going over it! That's true! I just want to filter out strings (i.e. data types that could be dangerous). Also, couldn't I use is_array to validate that the checkbox POST data is an array? Thanks Antonio
  2. Antonio, Thank you very much! That answer was far more than I expected! I just had a quick question: Is it better to use is_int or is_numeric? I was doing research about this before and several sites said that is_numeric is better because is_int will look at a string of numbers (which is what is contained in the array) as a string and not an integer (thereby returning a false answer). What do you think? Anyway, thank you again for an awesome and well thought out answer! Matt
  3. Larry or Antonio, I haven't been on here in a while and I apologize. Been busy with work and web dev! Hartleysan and I have been working on a site and I had a question about validating checkbox data. Larry doesn't cover this in his books (no offense at all, Larry) and it is something that is new for me. What I have is a checkbox group with values that are all integers. There are two things that I want to do before storing the data in the database: 1) I want to make sure that the $_POST variable is an array. 2) I want to check that all the values in the array are integers. I did a Google search and found an answer on Stackoverflow http://stackoverflow.com/questions/306252/how-to-align-checkboxes-and-their-labels-consistently-cross-browsers , however, it seems overcomplicated. The guy who answered the question uses the following code: function for_all(array $arr, $func) { return array_reduce($arr, function ($a, $v) use ($func) { return $a && call_user_func($func, $v); }, true); } var_dump( for_all(array(1,2,3), 'is_numeric') ); //true Is this level of complexity really necessary to just iterate through an array and check if every value is an integer? What do you guys think about this?
  4. Larry, I took a look at the code again this morning and I think I figured it out! As I said, only the CREATE and UPDATE functions don't work with your Flex app. and AMFPHP 2. Those are the only 2 functions which are receiving data to be inserted into the database. I thought that it was possible that AMFPHP 2 has changed from passing an ActionScript object to PHP as an associative array and now appears to pass an ActionScript object to PHP as a "generic object" (like Zend does). I changed the PHP code to reflect the changes you make to the script on page 307, uploaded it, and it worked as expected! I did look at the AMFPHP documentation to see if this is mentioned, but as I said above, the documentation is a bit high level and vague. They mention several new data types, but don't seem to mention anything about a "generic object". Here is the documentation on AMFPHP 2 data types: http://www.silexlabs.org/amfphp/documentation/data-types/ Is the "undefined" data type a "generic object"? What can you make of all this Larry? Matt
  5. Larry, Thank you for your response! I set up the database for the chapter 9 products app on my hosted server and got AMFPHP 2 installed. When I tested the app, everything worked fine except that I could only READ and DELETE records. This was strange, and I thought I made a coding mistake, however, when I went into the browser and tested the CREATE and UPDATE functions they worked fine. Having tried everything, I then decided to install and test with AMFPHP 1.9. I set it up in about 5 minutes, changed the url in the flex app., uploaded everything and it worked perfectly (with CREATE and UPDATE working as expected)! I don't know what to make of this! Something is definitely going on with AMFPHP 2. Here is the link to the AMFPHP 2 browser on my server: http://www.tuesdaygi...ervices/Amfphp/ (I'm trusting that this won't get abused, but posted it so others can see the browser for AMFPHP 2.) It appears that they have done away with using a Flex app. to test the functions and now everything is done with HTML/PHP. Also, notice that the url is index.php. The AMFPHP site is pushing everyone to upgrade from 1.9 to 2.0, however, after what I've experienced I'm not too sure what the benefits would be. Also, it appears that there is some transition in ownership of the project and there is a new website: http://www.silexlabs.org/amfphp/ I thought about making this a new thread because I feel that it is an important change to AMFPHP. New users who try to use the book's examples with AMFPHP 2 will certainly experience the same headaches I did. The only thing I can suggest is just staying with the older version. If you have some time Larry, you might want to look into this. I would love to hear your thoughts and advice about this! Good idea! My use case is, in fact, very simple. I am just reading in a list of file names from a database and using it to populate a drop-down list, so nothing too complicated. I will just use your code then! Thanks again, Matt
  6. Hi Larry, Sorry I haven't been around here in a while. I've been working on other stuff and busy with work! I just started reading your book again and went through chapters 7 and 8. I wanted to say that the whole data services with Flex thing can be a bit overwhelming at first, how ever I think you did a fantastic job of teaching it without skipping over any important information (which other books I've seen have done). It's all making perfect sense so thank you for that! I'm on chapter 9 now and getting into RPCs with AMF. I had a couple of questions: 1) It appears that AMFPHP 2.0 is out now and a few things have changed. The gateway.php file is now gone and the documentation is sparse at best. I had to go into a forum to figure out what they could have taken 5 minutes to explain in the "Installation Guide". Anyway, it's now just called index.php in the Amfphp folder. You can also go directly to this page to see the "Services Browser". The documentation also says that on a production server, you should copy this file and your services to folders outside of Amfphp. I understand what they mean, but I don't want to break anything. I just wanted to get your take on this. Is there anything I should be aware of? 2) I am testing on a remote server, so I don't have a WAMP environment set up. Is it possible to use the Flash Builder Data Service wizards to generate code if you are working from a remote server? Also, I don't want to install the Zend Framework because I don't want extra convoluted framework code taking up space on my server when I only need the AMF services. I want to use AMFPHP if possible. Is there any benefit to letting Flash Builder create my service code, or is the code you wrote good enough? 3) I downloaded the example code for the book and noticed that if Flash Builder writes the code, it doesn't seem to use the RemoteObject component, but uses a CallResponder instead. What is that? Why wouldn't it use a RemoteObject? Is their any benefit to using one or the other. This is one reason why I don't like to use wizards for stuff like this. They use/do things that one would not think is the way to solve the problem and they hide certain things in the background! Sorry for the long comment! Thanks in advance Larry! Matt
  7. Larry, I have been working on this chapter as well, and although I haven't ran into any trouble, I still am curious about the following: private function getDepartmentsResult(event:ResultEvent):void { departmentsList= event.result.department; } If that was the line you were referring to, it comes straight out of your book (pg. 249). Why is it not beneficial to do it this way? I would think it's better separation of code.
  8. Thank you all for the great input! @Josee - Yeah, I did something similar a while back to see what the difference between !isset() and empty() was I have never heard of ctype before. Thanks for that! Matt
  9. Larry, I am using the first example from the book as the basis for a site I'm making. I noticed that you are just using standard queries for everything (registration, login, etc...) Would it be better to replace all those with prepared statements? As you said in your books, they prevent SQL injection attacks and can have a performance increase. Would there be any disadvantages to using them? Thanks, Matt
  10. Jeg er 1 / 4 norsk, og jeg bodde i Stavanger i 6 måneder. Jeg boddesammen med venner. (I can read and write basic Norwegian, but I still use Google translate to make sure it's correct ) Yes, the name Antonio can be a bit misleading. Hartleysan told me you were Norwegian! One more question: Would it be better to use isset() in this case? I think that's what Larry uses in PHP6 and MySQL5 for Dynamic Websites: Visual Quickpro Guide. Matt
  11. Thanks Antonio! So I'm taking it that using If(!empty($_POST['contact'])) is better because it not only checks that the array key exists, but that it is set also? btw - Er du Norsk?
  12. I had another question. I was looking at the way other people have implemented checking for hidden inputs and I found that there are two ways to do it. Here is an example form: <form name="contactus" method="post"> <input type="text" name="email" /> <input type="text" name="subjet" /> <textarea name="message"></textarea> <input type="hidden" name="contact" value="1"/> <input type="submit" name="contact-submit" value="Send Email" /> </form> Some just test if the hidden input is empty in the $_POST array: if(!empty($_POST['contact'])) {... And others use the "array_key_exists" method: if(array_key_exists('contact', $_POST)) {... Which way is better? Are they both the same? Thanks, Matt
  13. Thanks Antonio! No, I don't display the login form once the user is logged in. However, I am using the modular site design that is in Chapter 3, so everything is being processed within one page. Anytime the page is reloaded using the POST method it has a listener within conditionals to see which hidden input was sent. Also, a guest can leave a message on the page and this will require a second form as well.
  14. Larry and Josee, I see your point! I'll use the hidden inputs. Thanks, Matt
  15. Yeah, I agree, and was torn between both solutions. After doing some more research I found out that the "hidden" input method used to be the standard way to detect multiple form submissions on a page. However, the new way seems to be to use the "submit" input field. It is much cleaner and apparently all new browsers support it. According to W3Schools browser statistics, IE only has 22% of the browser market now. IE is loosing it's position big time, and it's about time. Due to these pressures, and the growing usage of competitor's browsers, I think Microsoft is finally getting their act together and creating standards compliant browsers. As far as IE6 and before, my only response is to upgrade to a proper browser! I think I speak for the world when I say that I am tired of playing the compatibility game with IE Anyway, things have certainly changed since "PHP 6 and MySQL 5" QuickPro Guide came out, so this would be a good time to see what Larry has to say on the topic. May be we can even take a poll in the forum: "hidden" vs. "submit"
  16. Thanks Josee! I did some searching and found this page: http://bavotasan.com/2009/processing-multiple-forms-on-one-page-with-php/ Matt
  17. Hello all, I need to include 2 forms on one page. One will be a login form and the other will be a form for the logged in user to change his profile. The site is a modular design, so all links (including form submissions) will call the same page. The problem is this line of code which handles whether a user has submitted the login form: if ($_SERVER['REQUEST_METHOD'] == 'POST') { include ('../../includes/gallery_login.inc.php'); ... } This is fine if the user is logging in, but what if they are submitting the change profile form? Does anyone know the best way of handling this? Is it possible to check the POST data to determine which form was submitted? Thanks, Matt
  18. Hello and sorry for the late reply! Jon and I did indeed "kiss" and makeup We have a tendency to get at each other sometimes, and I was in a bit of a hurry trying to get a solution when I wrote this post, so my apologies again for being over abrasive with him. @Antonio - Thanks for the help and the kind words (I get pretty unsure of myself sometimes and it's probably not a good thing)! What I ended up doing was creating a separate query as I had originally thought about. I called the result set from query one $result_1 and the result set from query two $result_2. Then I could use the data in them anywhere I wanted. I know it was a confusing situation and I apologize for that. I think the confusion comes because the site is modular, so the same page is being called each time with different content being loaded depending on which links were clicked. Also, there is additional content for a user who is logged in and viewing their page. Basically that second query will only be called when a user has that boolean variable set as true (it's a flag set by the admin. to approve the user so he can post content). I hope that doesn't sound more confusing than it already does! Thanks again, Matt
  19. Really? I take the opposite to be true! The offending line was: "If that's not a viable solution, please explain why, because otherwise, I think you're the one that is wrong." You may talk to the new people in this forum that way (which I've repeatedly told you not to do), but you will not talk to me that way in a public forum! Why does everything have to be a debate with you? You sound like a 5 year old who is trying to prove to himself, and everyone else, that he is the smarter one in the class! Personally, I really don't care! I was simply asking a question and was trying to get an answer to it, but since you have managed to drag this thread down the toilet I guess it should end here! As far as not explaining the problem well enough, I have tried to do so; not once, not twice, but three times! Josee seems to have understood it! I want to apologize to Larry and everyone else for letting things get this far.
  20. Jon, Sorry to offend your Japanese sensitivities, but I don't know how to get small 'つ' on this keyboard! What are you, Accenture Consulting? Nowhere in my original post did I ask for you to reevaluate my query structure or redesign my site. Believe me, with an IT degree, 4+ years of PHP and MySQL experience under my belt, and having read 3 of Larry's books from cover to cover, I don' think I need you to tell me how many queries I should have on a page, nor how to rewrite them! If I do, you'll be the first one I ask (after Larry, Stuart, and Antonio, of course)! Dude, doesn't someone in the Ajax forum need help? Thank you very much Josee! That might just be the best option for my situation! Matt
  21. Jon (HartlySan)... good friend of mine... I'm banging my head against the desk here! Only if you mean the "profile" page, which is the first one users see when they go to a gallery. That data could certainly all be pulled in the same query. However, you of anyone should know the layout of this, and when it comes to displaying all the images in a user's gallery, or videos, or a form to add images or videos, then entirely different queries are going to have to be used. 分た? Here is a more in depth illustration of the problem. Query to populate header: $q = "SELECT galleries.gallery_id, galleries.user_id, galleries.gallery_name, galleries.logo, galleries.status FROM galleries WHERE galleries.directory_name='$dir'"; $r = mysqli_query ($dbc, $q); The returned data is then used in the header. In the "content" section of the page I would run a query like: $q = "SELECT images.user_id, images.title, images.temp_name FROM images LEFT OUTER JOIN galleries ON galleries.user_id=images.id WHERE images.gallery_id='$gallery_id'"; $r = mysqli_query ($dbc, $q); Now, in the nav. section, which is in the footer, I use the "status" field from the first query to set up a link. Do you see the problem now? The two queries are vastly different in the information they are trying to gather, so a single query would be out of the question. This isn't a difficult problem, by any means, but I just want to know how others handle it. I am starting to conclude that using 2 different variable names for each result set might be the only option. Larry, Antonio, Stuart, what do you think?
  22. I'm not populating the nav. area with "a second query". I'm using a value from the first. (see above) I'm already doing that! HartleySan, I appreciate your trying to help, but I feel that things are getting a bit off target and I am not really in the frame of mind to start explaining myself. The problem is very straight forward. Perhaps I should have explained it better, and I do apologize. What the first query is for is simply to grab the name of a person's page (this is for the gallery site I have been working on), the name of the file used for their logo, their first name, last name, and a boolean value. All of that is used in the header of the page and the boolean value is used in a conditional in the nav. menu. The second query is used for the content on each page. The reason I can't use a view, or a single query, is because the query is different from page to page (for the person's profile, to display an image gallery, to display videos, etc...). I just wanted to know what the "best practice" was for calling another query in the midst of using the result set from another query. I know the answer is probably very simple, and there are certainly many solutions, but I'm sure this situation is very common and I just wanted to know if there was good way of handling it. Thanks, Matt @Antonio - I misunderstood what you were trying to tell me before. In this particular there's only one record returned, so I wouldn't even need an array, but your solution is perfect for more than one record and I will keep it in mind in the future! Thanks!
  23. Thanks Larry and Antonio, Basically, I am using the first query to populate a user profile page (first name, last name, pic, etc...), so it will return only one record each time. The second query is based on a boolean field in the the result set of the first query. It also will return one record. The results of that record will be used before moving on to the nav. section, which will use a row count check from the first query to determine whether a link should be created or not. I talked about this with HartleySan and he suggested creating a view of all tables involved and then performing one query. However, I think views are only appropriate where you need to perform multiple queries on a certain set of data and display it. They create a host of issues when you edit the underlying tables as well. I think that might be overkill for this situation. I did come up with a "workable" solution, which was to store both queries in different result sets ($result1 and $result2). However, I tend not to like "workable" solutions as they are almost always also "half-ass" solutions! Thanks Antonio, but wouldn't this be a more involved way of doing the same thing I did above with the two result set variables? Do you mean so I can iterate through the data? Each query will only return one record. Sorry for not being clear about that above! Thanks guys, Matt
×
×
  • Create New...