Jump to content
Larry Ullman's Book Forums

Matt

Members
  • Content Count

    173
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Matt

  1. Chapter 17 Specifically what you are looking for is: pgs. 558-560 ("browse_prints.php") pgs. 561-568 ("view_print.php" and "show_image.php")
  2. I am working on a site which uses the site modularization from Chapter 2 (thanks Stuart for the help with that). The problem I am having is that I need to run a second query within the "result set usage" of a prior query. What I mean is that I will run the first query, and then depending upon a boolean value from a field in the result set, I will run a second query. The problem is that once the second query is finished, I need to continue using the result set from the first query to construct a navigation menu in the footer.php file. Here is pseudocode to illustrate: 1) The first query is ran 2) Some of the result set of the 1st query is used to generate page content 3) Within a conditional (which checks a boolean result from the first query) a second query is ran 4) The results of the second query are displayed 5) The results of the first query are then used to build the nav. section Specifically, within the navigation section I'm using: if ($rows == 1) { ...display link } That creates a huge conundrum since the $rows variable for the first query will be destroyed upon execution of the second query! I imagine that I can put the result set of the first query (including a flag variable for "if ($rows==1)") into variables, then I can access them from anywhere in the page. Or, can I store the result set from the first query into a different variable than the result set of the second query? It just seems like there has to be a more efficient way! Has anyone ran into this situation before? What would be the best way to get around the problem? Thank you very much in advance for any help or advice, Matt
  3. Larry, I didn't know that, but it makes sense! Thanks for the clarification! Matt
  4. I had no idea this was the case, but it all makes perfect sense now that I think about it! You definitely know your stuff Stuart! Thank you! Matt
  5. So I should be using the BASE_URI then? Thanks a lot for that Larry! Very much appreciated! Matt
  6. Stuart, Thank you very much for your help! The code works perfectly! However, I have just discovered a strange problem with using the $_GET method. I am using the following code at the top of the script to check which type of request method was used (i.e. GET, POST, or none) and it works fine: if ($_SERVER['REQUEST_METHOD'] == 'POST') { include ('../../includes/gallery_login.inc.php'); $include = 'gallery_content.inc.php'; } elseif (($_SERVER['REQUEST_METHOD'] == 'GET') && isset($_GET['p'])) { if (array_key_exists($_GET['p'], $pages)) { $include = $_GET['p'] . '.inc.php'; $page_title = $pages[$_GET['p']]; } } else { $include = 'gallery_content.inc.php'; } However, if I take out the "&& isset($_GET['p'])", then the page throws the following error: An error occurred in script '/var/www/html/includes/show_gallery.inc.php' on line 43: Undefined index: p It's almost as though the page defaults to using the GET request method on first load (when 'p' has not been defined yet) and throws an error. By including the "isset($_GET['p'])" in the conditional it knows that the $_GET array is empty and then moves on to the "else" conditional. This is very strange behavior! The first time the page loads, it should not be via the GET method, and "$_SERVER['REQUEST_METHOD'] == 'GET'" should be false. Does anyone know what is going on here? Thanks, Matt
  7. Well, here we go with the absolute path errors again! In my file I'm trying to include the following file: include ('http://' . BASE_URL . 'includes/gallery_login.inc.php'); Here is my BASE_URL definition in config file: define ('BASE_URL', 'www.tuesdaygirl.org/'); Which a third grader could tell you should result in this: http://www.tuesdaygirl.org/includes/gallery_login.inc.php However, once again, error, after error, after error!!! An error occurred in script '/var/www/html/includes/show_school.inc.php' on line 37: include() [function.include]: URL file-access is disabled in the server configuration Array This makes absolutely no sense! I gave up doing this a while ago because of the same errors, however, I thought I'd give it another try. Unless anyone has any ideas for why this ALWAYS generates errors, I guess it's back to '../../includes/etc..." Thanks, Matt - Larry, the "absolute" vs. "relative" path topic (and the many mind bending frustrations that go along with it) has come up time and time again in this forum! I feel that it really needs a thorough going over in the next edition of one of your PHP books!
  8. HartleySan and Stuart, Thank you both for your input on this! Stuart, your solution is brilliant! HartleySan, I know you don't have this particular book, but by matching the page the user is trying to access with a value stored in an array (or in Larry's case, by using a switch statement), there is absolutely no way that anyone can access content they're not supposed to! Stuart and Larry are pretty much doing the same thing, except that Stuart further restricts users to certain pages based on whether they are logged in or not, which is essentially what I was trying to accomplish. I agree! Thanks a lot! Matt
  9. Hi Larry, Sorry I've been away from from the forum for a while. Was taking a break from php and busy at work. What I am trying to do is merge the example on Website Modularization in Chapter 2 with your code from Site 1 from the E-commerce book. The modularization code is straight forward, however, what I want to do is limit the pages which can be accessed depending on whether a user is logged in or not. I'm still in the brainstorming phase, but I imagine that since the login form is in the footer, then that can be left as is and won't affect the code which handles the "modularization". However, how would I best handle restricting the access of a "content module" only to a user who has successfully logged in? I'm just afraid because the page that is trying to be accessed is passed via the url. I can control the links displayed in the footer based on whether the user is logged in or not, but what if they try to hard code a page they are not supposed to access into the url? Am I correct in thinking that I should just use a conditional to check whether a session variable is present or not before loading the content module for a restricted page? For example: case 'somePage': if (isset($_SESSION['user_id'])) { $page = 'somepage.inc.php'; $pageTitle = 'Some Page'; break; } else { $page = 'main.inc.php'; $pageTitle = 'Site Home Page'; break; } Or would there be a better way of doing this? I only need to restrict 2 pages, so this shouldn't be too complicated! Thanks in advance for any help you can give! Matt
  10. Interesting point, however, "Primary Key" is the standard naming convention used in all RDBMSs for the column which uniquely identifies each record in the table. Also, thanks for the link!
  11. HartleySan, Thank you so much for this! Since I will only be checking one field the code will be even easier! I could just return the whole query result from Ajax. Are query results delimited by anything besides whitespace? Should the following line read: var aSeparatedData = oAjax.responseText.split(' '); // oAjax is your Ajax object. Matt
  12. The problem is that the onChange event is being fired when the user clicks outside of the text input field, therefore, they are not getting Ajax updates as they are typing the characters, but rather after they have finished typing and clicked somewhere else. This is far too late in my opinion! What about doing the query, which selects all the usernames, when the page first loads. The query results are then put into an array. Then, I could use the onKeyUp event to constantly check the arrays and show the messages. Since it is all being done on locally on the user's machine, then there is no unnecessary stress being put on the server!
  13. Thanks Paul! Since I'm pretty new to javascript, I really appreciate the code example! I'll try it out! Matt
  14. Well, it does look awesome, and it works like I want, however, I see what you mean! What are the alternatives then?
  15. I made the changes and it works perfectly! The only problem is that, if at any time you hit the ENTER key while you are focused on the "username" field, the Ajax message will disappear. The only way to make it return is to click back in the "username" field and start changing the value again. It's a minor problem, but it obviously isn't going to be acceptable on a live site! Is there any way I can re-trigger the Ajax request whenever the user hits the ENTER key, or is there another solution to this problem? I have a lot of programming experience, but I'm pretty new to javascript (well, not entirely new, but for years I have avoided it like the plague), so I apologize. Thanks, Matt
  16. Jonathon and Josee, Thank you both for the helpful advice! I will try your ideas and let you know how it works out! Thanks again, Matt
  17. Hello everyone, I have tried the first Ajax example in Chapter 13 and it is working fine! The problem is that I want to use this code for an actual site I'm developing and there are two problems. 1) The screen updates are too slow. I originally thought that the onChange() event was fired after each keystroke, however, what I figured out is that the event is fired only when a user focuses out of the "username" input field. This can be confusing to the user! Let's say he/she types a username and then focuses on the next field. At that point a "Username is unavailable!" message is displayed, so the user goes back to the "username" field and starts typing in a different username. Until they click on a different input field the "Username is unavailable!" message will will still display, even if they have changed their username to one that is available. Any ideas how I might improve the speed of the Ajax updates? I talked to HarleySan and he suggested that I could run a query once when the user first goes to the registration page and load all the usernames in a javascript array. Then, it could do everything on the user's local machine and give character by character feedback on the availability of a username (similar to how the google searches work). I thought about changing the onChange() event to a keyUp() event. I realize that it will put a bit more strain on the server as a new query will be run with each keystroke, but users will only register once, and the site won't have 1000's of people registering each day, so I don't think this will bring the site down! 2) I want to add styles to the Ajax messages (i.e. red or green based on whether the message says a "username" is available or not). I tried to add a style to the <span> elements where the messages are displayed, however, because the page is not reloaded every time the message is changed the styles are not going to be interpreted. It's almost as though the messages displayed by Ajax exist outside of the web page and are not parsed as part of the page. How can I add styles to the messages? Should I add the styles to the echo statements where the messages are actually created inside the checkusername.php page? if (mysqli_num_rows($r) == 1) { echo '<span style="color: red";>The directory name is unavailable!</span>'; } else { echo '<span style="color: green;">"The directory name is available!</span>'; } Can I even embed a <span> inside of another <span> (there is a <span> element on the form where these Ajax messages are displayed)? Is there another generic css element I could use? Any help would be greatly appreciated! Matt
  18. I've got it! I think I'm going to have about 8 constants for the various gallery includes (header, footer, content,etc...), but I don't think this will be a problem. Thanks Larry!
  19. Sorry to attack you earlier HartleySan, but I am just really careful about questioning people's background knowledge, especially since the MikeMikeMike incident (and Mike made it clear in his posts that he was having a hard time with some of the more fundamental concepts). I was new to this forum a couple months back and got a bit of the same "newb" treatment, and I have an IT degree and have read several of Larry's books! Anyway, page 265 of the E-Commerce book has an excellent example of a multiple INSERT stored proceedure - HartleySan, I do have Larry's book in front of me right now
  20. HartleySan, I apologize for interjecting here, but why are you questioning his logic? Nick obviously knows what he's doing! This situation happens all the time and has nothing to do with proper normalization! If anything, normalization (which I am in no way saying shouldn't be done) can exacerbate the problem. I dealt with a similar situation recently with my gallery creation pages where I was going to insert data into the "galleries" table and "profiles" table after the user had gone through a process of filling out a form for both!
  21. I think I understand what you want to do! Are you saying that you want to perform an insert into 2 tables at the same time? There are a couple of solutions to uploading to two tables at the same time. 1) Perform 2 separate INSERT queries using standard sql. 2) Use a stored procedure. The added benefit of using stored procedures is that if any part of the query fails, then the whole thing can be rolled back. Is this what you want to do? Matt
  22. Jonathon and Larry, Thanks a lot for your help! Ok, I'll convert everything to absolute paths! Also, Larry, when you say create a constant, you mean one for the "includes" folder right? My "includes" folder is getting pretty filled up with files. I'm starting to think I should also create a separate one for the gallery files (i.e. "gallery_includes"). This way the site will be more compartmentalized and better organized. Yeah Jonathon, I heard that you can set up include paths in .htaccess files. Is this what you were referring to?
  23. Thanks Larry! Sorry I didn't respond sooner. Just to clarify, for each include I would do the following: include (BASE_URI . 'html/includes/gallery_content.inc.php'); There is also the paradox of how to include the config file. Should I use: include ('home/tueslcom/html/includes/config.inc.php'); or include ('../../includes/config.inc.php'); I know that most of this is just semantical, but I think it is still important and others can learn from it. Thanks again Larry, Matt
  24. Larry, I hope this doesn't sound too moronic on my part (since databases are more my strength), but I notice that you use "UNIQUE" to define indexes in "PHP 6 and MySQL 5: Visual QuickPro Guide" and you use "UNIQUE KEY" in the "E-Commerce" book. What is the main difference between the two? Are UNIQUE KEY indexes only applied to secondary keys, or are they just a way of defining another key in a table (which could just as easily be done with UNIQUE or KEY)? Information online about the differences between these is really sparse, so if you could elaborate on this I would be extremely thankful! Thanks, Matt
  25. Thank you so much Larry! I agree about using absolute paths. I just did it this way when I was developing because it was the only way that worked without too many headaches! I had originally tried to use absolute paths in the include statements, but kept getting errors. Doing the following: include(BASE_URL . 'includes/something.php'); ...always caused errors! I will try it again and see if I was overlooking something. Should I use 'BASE_URI' instead? Which is better? This can get quite confusing! Or, should I define a constant like this: define('INCLUDES','www.example.com/includes/'); Also, I did a Google search for including files with absolute paths and it gave a few different results for how to do this, and it illustrated what a hideous and overcomplicated mess people have made using php to set up "absolute paths"! The most common solution seemed to be: define('ROOT', $_SERVER['DOCUMENT_ROOT'); and in the including file include_once(ROOT."/includes/someFile.php"); ...or by defining the path to the 'includes' directory by putting the following code in a config file in that directory: define(‘ABSPATH’, dirname(__FILE__).’/');] ...and then including the config file and another file: include('config.php'); require_once(ABSPATH . 'somefile.php’); I personnaly think your way of hard coding the constants in a config.inc.php file is the best, but I just want to get your take on these other ways of doing it. It just seems like people try to make things more complicated than they need to be. Thanks Larry, Matt
×
×
  • Create New...