Jump to content

ManiacDan

Staff Alumni
  • Posts

    2,604
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by ManiacDan

  1. Sessions are tracked using a cookie. A session is what's used to maintain a user's state through a single "visit" to your website, which can span multiple page loads. Without a session, you have no way of knowing that the user is returning to the site over and over again. Once the user closes his browser window or turns off his computer, the session is destroyed (there are other ways for this to happen as well). You can set an "auto-login" cookie to log the user back into the site the next time he visits automatically. This is a security risk though, so make sure to read up on how to properly do it so you don't end up passing dangerous data in the cookies. -Dan
  2. You're looking for the JOIN syntax -Dan
  3. As an aside: If your column names are actually "column1" "column2" etc, you're doing it wrong. -Dan
  4. You can avoid this entire problem by thinking about your architecture: If your form re-submits to itself, then the same code will be running. Put this code that generates $concertDates at the top of the script, before any if/else check to see if the form has been submitted. That way, $concertDates will be available no matter what path this form takes. As for sessions and cookies: The web is stateless. Once you get a page, the script that made that page is dead and the web application will never know who you are when you submit the form. We solve this problem by keeping a unique identifier in the cookies so we can track a user's progress through the site. This, when combined with a set of data that's necessary to maintain a user's state, is called the session. Generally it's done using cookies. Rarely, it's done with the session ID in the URL. This is generally considered a terrible, terrible idea, and is turned off by default in PHP. It breaks bookmarking, and if a user emails the URL of your site to someone else, the recipient will automatically hijack the first user's session (since it's part of the URL). If your users have cookies off, they're not browsing the web properly anyway. They wouldn't be able to use phpfreaks, facebook, or even gmail. Without cookies, the web is static and impersonal. If they want to use the web, they'll turn cookies on. Don't even bother writing for cookie-less users unless you discover it's a major portion of your userbase. -Dan P.S. Yes, the same ManiacDan from DevShed, I'm a mod over here as well. We do want to help.
  5. The arrow syntax $object->var->var is for OBJECT, the bracket syntax $array['key']['key'] is for ARRAYS. You cannot use the object syntax on an array, or the array syntax on an object (unless you implement the proper interfaces for that object). You can, however, have an array of arrays of objects, or an object containing an array. The key is to use the proper operator for the job. Also, you need to start developing with error_reporting turned all the way to E_ALL, so that you'd get the proper error about using an object operator on a non-object. -Dan
  6. Nested loops are almost always a bad idea. What you should do is pre-process your query data so that you get a nicely formatted "lookup array," where the key to the array is the product ID you're getting from this $_POST['check'] array, and the value of the array is itself an array that features the data you need. Your echo would then look like: echo $data[$product]['price'] . " " . $data[$product]['currency'] . " for " . $product . "<br />"; -Dan
  7. Show the results for SHOW CREATE TABLE on this table. Did you make sure you only had ONE database and database server? You're not inserting into test and checking production or anything like that? --Dan
  8. He means to paste it inside [ code ] tags. Also, are you sure you're in the right database on the right server? Your PHPMyAdmin instance is probably running on the local MySQl server, the PHP script could be connecting to another server entirely. -Dan
  9. You have to use javascript to do calculations without page refreshes. javascript is a language that exists inside your HTML document and is executed on the client's computer, not on your server. -Dan
  10. I see probably 1,500 lines of code without a single error reporting function. How have you been doing this for "so[ox5] long" without using mysql_error() ? Have you tried that? Have you turned error_reporting all the way up? Have you tried putting debug echoes in this script to see what the values of everything are? ereg is deprecated and should not be used. Since you don't know that, I'm assuming your errors are set to a level that hides the deprecation warning. Set error_reporting(E_ALL) at the top of your script, and make use of mysql_error(). -Dan
  11. If the printer is hooked to your SERVER, you should be able to spool directly to print jobs on the command line without using socket connections. If the printer is hooked to your CLIENT (the computer you're using to view these reports), you can invoke the print dialog in javascript when you need it, then just click "ok" and it will print. -Dan
  12. You can make a column in MySQL that will default to the insert time for that record, it should be a pretty easy change for you. -Dan
  13. Yes, your items should have timestamps associated with them. Just about every database table should have a create_date column, you'll find some use for it. -Dan
  14. Why are you even doing it like this? There's usually no reason to store repeating data in large numbers of columns like this. That's why databases have ROWS.
  15. You could avoid this entire problem by using the proper format for date() on the first page that you set this variable on. There's no reason to set $_SESSION['date'] to a formatted string you have no intention of using, only to convert it back to a timestamp and then into another formatted string later on. -Dan
  16. <?php echo date('F j, Y', strtotime($_SESSION['date']));
  17. Ok, a number of things: 1) You could very well use the PHP variable syntax and run it back through the PHP parser to let PHP handle your interpolation, but that's dangerous and unnecessary for such a simplistic task. 2) You're honestly saying that you will not know ahead of time what these content blocks will be named? They could be anything? How are you planning on generating code if someone drops in a content block like {block type="my_new_block" name="The Page"} ? What will your code do? Maybe that's the question we should have asked from the beginning. How will you be filling in custom block names? If you have a database table full of content block names...we're back to my str_replace suggestion. 3) Just because it's regex doesn't mean it's more complicated or more correct. Regex is a last resort. It's slow, cumbersome, confusing, and prone to errors. XML parsing would work better if this is pure namespaced HTML (which it appears to be) and str_replace will be the absolute fastest route. -Dan
  18. Why do this at all? Why not simply use PHP variable names? <div id="wrapper"> {$leftSideBlock} {$contentBlock} {$rightSideBlock} </div> You will have a fixed set of content blocks. str_replace will do this for you easily. -Dan
  19. It's sloppy to use two, but I'm going to lunch and can't be bothered. I'm pinging requinix though, it's like the bat signal, only for regex: $string = '{block type="left_side" name="Left Side"}'; preg_match('/\{block ([^\}]+)\}/', $string, $foo); preg_match_all('/([^=]+)="([^"]+)"\s*/', $foo[1], $bar); foreach ( $bar[1] as $k => $v ) { echo "{$v} = {$bar[2][$k]} <br />\n"; } -Dan
  20. What have you tried so far? This is relatively simple to parse just this tag. Parsing multiple tags in the same document which may or may not be nested or malformed is significantly harder, to the point where regex might not be able to do it. -Dan
  21. the preg_replace method is very slow and processor intensive, you probably just want a combination of strlen and str_repeat. That is, only if cssfreakie's solution isn't what you actually need. -Dan
  22. This is usually done with regular expressions, I imagine. -Dan
  23. (.*) <-- that selects as many things as it can, as long as the whole expression is still valid. Regular expressions are greedy, and will match things as wide as it can. You must use the "ungreedy" modifier to prevent this. Change (.*) to (.*?) -Dan
  24. There are special characters in regular expressions too. These characters must be escaped with a back slash: /?*$^. -Dan
  25. Look at your code. See how the coloring is wrong? That's because your string is wrong. If you use single-quotes ( ' ) to enclose a string, any single quotes inside the string must be escaped: ( \' ) -Dan
×
×
  • 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.