Jump to content
Larry Ullman's Book Forums

HartleySan

Members
  • Posts

    3047
  • Joined

  • Last visited

  • Days Won

    243

Everything posted by HartleySan

  1. All right, I'll take your word for it. Sorry for getting the topic side-tracked anyway. Thanks for explaining that.
  2. Well, if you think about your code logically, then that means that it's failing the next if conditional. Try echoing the three posted values to the screen before you hit the if conditional and actually confirm whether you're getting the intended values (mainly, the values are actual numbers).
  3. One quick bit of advice: I would not post your database connection details. You could just write something in the code like the following: $con = mysqli_connect(); // Database details go here. Also, if you want to actually delete the record, you'd have to set up a script that would automatically execute, for instance, once a day. The easier solution though is to always just test the user's registration date. For example, if said user has not paid for a full membership and their registration date was more than 24 hours ago, then do not allow them to view premium content, etc. Either way is an option, but performing the check each time is easier than auto-deleting "unneeded" records. And I say "unneeded" because what's to say that their login info is no longer necessary? Wouldn't you normally want to retain their login info, even if they haven't paid for said content? Edit: I didn't realize that Matthaus was answering your post too. Whoops!
  4. Oh, I just saw the other problem. PHP doesn't see "Submitted" and "submitted" as being the same thing. Be careful of the case.
  5. You need to use the value attribute of the input elements to echo ("sticky") values. For example: <input type="text" name="quantity" size="5" maxlength="5" value="<?php if (!empty($_POST['quantity'])) echo $_POST['quantity']; ?>" /> </p> That is just one example, and the syntax may differ, depending on your situation. Actually, I'm not 100% sure my syntax is correct, and can't reference the book at the moment, but that's the general idea.
  6. So product ID 1 in store A and product ID 1 in store B are actually different products? A bit confusing, if that's the case, but it's your database, so I'll trust ya.
  7. Long story short, the scope of your variable x is limited to within the checkName function. As soon as the setTimeout function is executed and set to x, the checkName function ends, and so does the existence of x. As such, x will never exist for the if test at the top of the function. I suppose the easiest solution would be to declare the x variable globally. I would start with that, and once you get everything working, then you can worry more about variable scope, which can be a tricky matter. Truth be told, in most cases, I see no problem with global variable declarations, even though hardcore OOP programmers would grate their teeth at such a statement. Either way, hope that helps. Also, I would preface all JS variable declarations with var. For example: [b]var[/b] x = setTimeout(function(){ // funky AJAX happens here }, 3000); Edit: Message board fail there with the bold inside the code. Larry, you may wanna have someone fix that.
  8. I have always wondered, is there a way to set up a mail server with XAMPP? It seems like one is built in, but I have no clue how to configure it for sending emails to Gmail, for example. Anyone have any experience with this? Thanks.
  9. The following link might be of use: http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/ Basically, I would use the JS setTimeout function and add a 3,000 millisecond pause, and then execute the proper function. By the way, why did you set first to the node.value, but last to just the node? Also, why did you put the getdata computation in parentheses? Just curious.
  10. I looked into that guy who made that regex tool, and apparently he's a big deal in the Flash community. Very interesting. I think I'm finally starting to become comfortable with regexes too. It's taken forever, but the old adage of "Practice makes perfect" is 100% true. It has been a frustrating ascension to comprehension at times though. Once you get them down though, you suddenly want to use regexes for everything (even when you don't need them). They're a lot of fun and super useful.
  11. The analogy I saw once regarding what NULL is is imagine a CD. A CD with no data on it is an empty string, and no CD at all is NULL. Anyway, what happens if a product exists in multiple stores? Maybe your example is just that, an example, but it doesn't seem like your database is normalized to begin with.
  12. The first thing I noticed is that you have two "value" values for the first input in the first script. That's not gonna work. Also, I am still a bit confused by what you want to do. Basically, you want to grab a bunch of sentences from a database, throw one of them into a DIV, and if the user presses the "Adjust" button, you want to be able to edit the sentence in the box above the DIV, and if the user presses the "Next Sentence" button, then you want to be able to get the next sentence and display it, right? Please let us know if that's what you want to do or not, and then we can point you in the right direction. Also, I would recommend getting this to work with just PHP first, and once that's working, you can add the Ajax layer at a later time. Using just PHP will force you to reload the page with each button click, but there's nothing wrong with that. Edit: As an afterthought, if what I mentioned above is what you want to do, it'd probably be more user-friendly to display all the editable sentences at once, place "Edit" buttons next to all of them, so that the user can easily see everything and choose what they want to edit.
  13. By the way, Bennie8, I didn't mean to come down hard on you or discourage you. It just seemed like you were mixing things up. Taking things one step at a time, and mastering the basics first seems like a more logical progression to me. That's all. If you'd like to explain in more detail exactly what you want to do, I think myself along with everyone else here could help you out. Thanks.
  14. Yeah, and that's what I'll probably end up doing to space things out a bit. I'm really picky about this sort of thing though, and I wanted to add spaces, not tabs, but I suppose I can't always have my cake and eat it too.
  15. Using that awesome tool you recommended, I was able to find what I was looking for. Here's the basic search and replace: <pre>([\s\S]*?)<\/pre> <pre>$1</pre> Because just about anything can go in pre tags, I had to be very vague with my regex, which makes it somewhat inefficient, but at the level I'm using it, I doubt the user will notice.
  16. Bennie8, sorry for sounding rude, but looking at the code in both your first and second posts, it seems like you do not understand how to use a loop at all. As Matthaus stated, you should use either a foreach loop or a for loop to go through each element in an array. Although, from what I can gather, you don't need to use PHP at all, unless you're using Ajax for some sort of database manipulation. Basically, you need to first capture all the "test" sentences/words, and store them in an array using jQuery/JavaScript. After that, you'll need to attach an onclick event to the "Next Sentence" button, so that a counter variable (e.g., i) is incremented by one each time the button is clicked, and then use that increment variable (i) to reference the correct element in the array. Anyway, without knowing exactly what you want to do with your code, it's hard to provide any more specific information. If I may be somewhat presumptuous though, what you're attempting to do seems a bit over your head. I mean, knowing how to loop through an array is a fairly basic principle, and if you're having trouble with that, I would recommend taking a step back, and practicing more with Larry's book before attempting what you want to. Lucky for you though, Larry's book is awesome, so you are in good hands if you follow along closely.
  17. Well, perhaps, but that doesn't work for me. I have essentially created a WYSIWYG editor, and I do a search and replace on double newlines with p tags, etc. Basically, everything is together in one string, and the amount of parsing it would take to achieve that isn't worth it. I think I have found another solution though. Will report back if I get it working.
  18. I basically have a bunch of pre tags surrounded by a bunch of p tags, and it's all stored in a string. For example, imagine the following stored in a variable called $string: <p>Text here.</p> <p>Text here.</p> <p>Text here.</p> <pre>Code here.</pre> <p>Text here.</p> <pre>Code here.</pre> <p>Text here.</p> <p>Text here.</p> <pre>Code here.</pre> <p>Text here.</p> Anyway, I need to use the htmlentities function or something similar on the code in the pre tags to get the code to display, but I'm trying to come up with a regex or set of regexs to separate the stuff within the pre tags with everything outside of it for getting the code to display. I was thinking about something like the following: $string = // The above HTML $pattern = '$<pre>(*)</pre>$g'; $replacement = '<pre>' . htmlentities('$\1$') . '</pre>'; preg_replace($pattern,$replacement,$string); Would that work, or am I just crazy? I'll keep spit balling, and posting my ideas up here as I think of them, unless someone can help in the meantime. Thank you.
  19. Yeah, that's what I was afraid of. I could also use or enter extra spaces and run them through some sort of entities function. Oh well.
  20. This may sound like a silly request, but I'm using PHP to generate a whole bunch o' HTML based on MySQL data. When I produce the HTML with the PHP, it looks fine on the screen, but if you look at the source, it's all bunched together, and really hard to read. If possible, I'd like to clean this up, so it looks something like the sample below. Any suggestions? Thank you. <body> <div> <h1>Important title here</h1> <p>The above title is important because...</p> </div> </body>
×
×
  • Create New...