Jump to content

denno020

Members
  • Posts

    761
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by denno020

  1. Give this a try document.getElementById("myForm").reset();
  2. You need to call session_start() at the top of every script that you wish to be 'login protected', so because of that, yes, you need to include init.php on every page. To check if a user is signed in, set a session array value with their username. Then at the start of each of your pages, check the session array, if the username value is set, (optionally) check that that username corresponds to a user in your database, and if so, you can show them the content that only logged in users can see.
  3. Personally, I use a simple math question, and I don't get any spam form submissions any more. Sure, it could easily be beaten by a bot that is written to specifically look for it, but for most bots, they don't seem to bother going to the trouble. I ask a question of, for example, 4 + nine (making sure one of the numbers is in written form). I hate captchas, so there was no way I was ever going to put one on my website. Another option that I've considered using is adding another form field, which you hide using CSS. This means normal users won't be able to see it, but a bot will see it, and fill it in. If it's filled in, then you know that it wasn't submitted by a human. Seems like a neat idea.
  4. This is fairly straightforward. You'll want to use window.setTimeout() for specifying how long to wait. The function inside of setTimeout will contain your redirect code. As for the loading image, just make that the only content on the page.
  5. The problem is because you're creating a new element, and then appending it. If you change it to use innerHtml for displaying the error message, then it will only show up once. if(document.getElementById('firstName').value == document.getElementById('firstName').defaultValue){ document.getElementById('output').innerHtml = "Incorrect information."; }
  6. Your code doesn't seem to work? Anyway, one way you could do it is to add your error message to a container of some sort, either a div or span, and then whenever the form is validated, the first thing you do is clear the content of that container. Then the validator will run as per normal, adding the error message to the container again if the form still doesn't validate. Something like <form> <div id="error-message"></div> <input type="text" id="the-input"/> <input type="submit" id="the-submit-btn"/> </form> <script> document.getElementById('the-submit-btn').onclick = function(){ document.getElementById("error-message").innerHTML = ""; //Perform your validation, adding the error message back to the container, if required } </script> That's obviously some really rough code, but hopefully it will give you the idea of what I'm suggesting.
  7. What's the effect you're after? I don't understand..
  8. Is there a reason you're not just using conventional array searching to find if the value exists? And then incrementing the count that way? Also, it would probably be easier to store the products in a single array like this: array( //item_id => quantity 1 => 4 ) That way you can do this to check if the item is already added: $sessionCart = $_SESSION['cart_array']; if (isset($sessionCart[$item_id])) { $sessionCart[$item_id]++; //I'm pretty sure this works.. echo "Item already added"; } $_SESSION['cart_array'] = $sessionCart;
  9. update your SQL so that you only find 1 user. so add a WHERE clause: "WHERE user.username = $username" where user.username refers to the table (user) and the field (username) that should match the provided username ($username) from the user through the login form I notice that you don't actually check credentials, i.e. password.. so you might want to look into that also
  10. Can you show us the 'pretty' version that doesn't work? Also, you're trying to set php variables and read from $_POST before you've opened the <?php tags.
  11. So the code you've just posted is quite confusing. First, $_POST['ran, ran1, ran2, ran3'] I really don't think that checks the 4 different POST array values.. That's checking for an array value with index "ran, ran1, ran2, ran3", which you definitely don't have. Break that up to be $_POST['ran'], $_POST['ran1'] etc. Second, you're not even doing any checking of the correct answer. Basically your code says that whatever answer they submit, they're right, otherwise, they're wrong. So if they don't provide an answer (or they load the page for the first time), they're wrong. Third, these lines: $ran = rand(1, 6); $_SESSION['answers']['ran'] = $ran; $ran1 = rand(1, 6); $_SESSION['answers']['ran'] = $ran1; $ran2 = rand(1, 6); $_SESSION['answers']['ran'] = $ran2; $ran3 = rand(1, 6); $_SESSION['answers']['ran'] = $ran3; will leave you with a session array looking like this array ( "answers" => array ( "ran" => X //Where X is the random number between 1 and 6 ) ) So you're only ever storing 1 value in the session array, and you're over-writing it each time, so only the last random number, $ran3, will ever be saved. Your code is actually quite a ways off what you require. You might want to go through it from the start and make sure you understand what you're trying to achieve.
  12. I have no doubt it works, but I asked if you could copy the dump and paste it here, so we can see the content of your array.
  13. Firstly, exclamation points on the Internet makes it seem like you're shouting, which in turn makes you sound ungrateful for any help I was trying to offer, even if it didn't help. Can you post the code that you have now.
  14. So the main thing you need to do is figure out how to remember the correct answer. There are a few ways it could be done, for example: using a database, using a plain text file on the server, using session variables. Session variables will probably be the easiest to set up in the short term. When you set your variables $ran, $ran1 etc., save them to the session like such $_SESSION['answers']['ran'] = $ran; $_SESSION['answers']['ran1'] = $ran1; //etc Then you can compare the values stored in the session array with those that the user provided. Have a crack at implementing something like that. If you need more help, just post what you're able to come up with, and I'll guide you some more. Denno
  15. What errors were you getting? Where is the code that you use to compare the expected value with the value that the user provides?
  16. What have you searched for on Google? http://stackoverflow.com/questions/17135829/sending-php-mail-from-windows-server
  17. I just tried this on my local machine: $data = array(4, 5, 6, 3, 4); function myarray (&$val) { $val=$val*2.0; } array_walk($data,'myarray'); var_dump($data); and it worked perfectly.. so, where exactly are you getting the error? And what is the full error? Can you also do a dump of your $data array before you perform the array_walk, and post that here, so we can see what it is before hand.
  18. add preventDefault() into the mix. $("").click(function(e){ e.preventDefault(); }); I'm pretty sure that does it.
  19. The problem is that when you add the click handler to .tagcan, there aren't any elements with that .tagcan class. When you add a tag, then an element is added with tagcan, however, the click handler doesn't get applied to new elements. What you need to do is attach the click to an element that is on the page from the initial loading. This is how you could do it: //this $("<span class=\"tag\" id=\"tag_" + t_t + "\"><font>" + tag + "</font><span class=\"tagcan\" id=\"" + t_t + "\">X</span></span>").insertBefore("#t_"); //becomes $("<span class=\"tag\" id=\"tag_" + t_t + "\"><font>" + tag + "</font><span class=\"tagcan\" id=\"" + t_t + "\">X</span></span>").appendTo("#t_"); Which adds the tags inside of a container. Then update your click like this: $("#t_").on('click', '.tagcan', function() { //The content of your function }); See how you go with that Denno
  20. I'm not really sure actually asked what you want.. But I'm going to guess that you want to load in a list of files from a folder, and display them on a page? Look into using glob();
  21. Do you see both of the ID's on the server? Or are you just going by what's displayed in your console? Every time you 'change your mind', and select a different option, your console.log will run, which is why you're seeing both 2 and 10. Move your console.log call into the .invite click function, and that will be the value that was sent to the server, as it will only be execute when you effectively execute the ajax. Hope that helps Denno
  22. Your OnlineOrders.php can be something like this <?php if (isset($_POST['submit'])) { //Check that a form has been submitted to the script //get all vars from the form using $_POST array. } That should get you started
  23. No worries, glad you worked it out Denno
  24. To get the value of any element that isn't an input, use .text(). You may also need to run parseInt() on the value before you can do a multiplication.. var num1 = parentLi.find(".num1").text(); var num1Int = parseInt(num1); var num2 = parentLi.find(".num2").text(); var num2Int = parseInt(num2); var answer = num1Int * num2Int; Try without the parseInt first, see if it'll work. I'm not sure off the top of my head. I'll usually just try it one way, if it doesn't work, then run with parseInt. This means you will also have to run parseInt() on the values that you pull out of the input field, before you compare their answer with the calculated one.
  25. Ok so to get the values for the multiplcation, you'll probably have to surround them in a <span>, give them a class (different classes), and then find them using the $parentLi that I showed you before. Here is how I think you should contain them: <strong><span class="num1">16</span> x <span class="num2">11</span> = </strong> Then update your jQuery to find those two numbers, perform the calculation, and store it in a variable called answer. You then compare this variable in place of the 176 As for the ID's, you probably don't required them in this instance. As before, any further questions, just let me know. Denno
×
×
  • 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.