Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by denno020

  1. 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
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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
  7. What errors were you getting? Where is the code that you use to compare the expected value with the value that the user provides?
  8. What have you searched for on Google? http://stackoverflow.com/questions/17135829/sending-php-mail-from-windows-server
  9. 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.
  10. add preventDefault() into the mix. $("").click(function(e){ e.preventDefault(); }); I'm pretty sure that does it.
  11. 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
  12. 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();
  13. 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
  14. 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
  15. No worries, glad you worked it out Denno
  16. 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.
  17. 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
  18. Good work. So from the looks of it you chose to use jQuery, at least that makes it nice and easy. As for your question about having to do it 10 times, no you don't. Instead of giving the button an ID of check, give it the class check, and then you can use that as the handler for the click Here is an example: <button class="check">Check</button> <script> $(".check").click(function() { var $button = $(this); //This is the button that was clicked on var $parentLi = $button.closest("li"); //Find the closest li parent, starting from the button, working up the DOM var value = $parentLi.find("input").val(); //From the li, work back down the DOM until an input field is found, and get the value of it }); </script> That's how you get the value out of the input field, then to display it, change the span ID of display to a class: <span class="display"></span> //using the variables from the previous code block, and therefore still inside the function for the click() var $displayField = $parentLi.find(".display"); //Starting from the parent li again, search down the DOM until an element with a class display is found $displayField.html(value+"<i class='fa fa-check'></i>"); //Set the value of the element that has the display class Obviously you'll use your if statements to display the check or cross appropriately. Don't get too worried about the way I've named my variables either. It's a notation that I've picked up through work. Having the $ at the start means it's a jQuery object, not a static value, but it doesn't matter how you name your variables. So provided each of your questions, answer fields and buttons are together in their own li, the code should work for however many you choose to have on the page. Let me know if you have any more questions. Denno
  19. I am about to go to bed, got notified on your reply just before I was about to shut down my PC, so to help, I will provide you with what you should search Google for. Ideally, I would suggest that you find some javascript tutorials on YouTube, users like Adam Khoury, mybringback, and JReam have fantastic tutorial series for beginners to follow. You're guaranteed to learn from their videos. As for your specific question, you will want to know these things from Google: "How to include jQuery" //Only if you choose to use the jQuery plugin, you could very well choose to use plain (vanilla) javascript "How to attach click handler to element with jQuery" //If you included jQuery above "How to attach click handler to element with vanilla js" //If you chose not to use jQuery "jQuery read value from input field" //if jQuery "javascript read value from input field" //if not "javascript addition" //This will be the same whether you choose to include jQuery or not. It's pretty much the same as other programming languages though "jQuery add element after another" //you will be looking for insertAfter() "vanilla javascript add element after another" If you can start with those searches, you should be able to figure out how to achieve your goal. If not, come back with the code that you try, and I, or someone else here, will be able to guide you further. The absolute easiest thing to do would be to choose to add jQuery to your project, and use the functions it provides, however using plain javascript will help you to understand what a plugin like jQuery does for you in the background. Hopefully that can get you started. Denno
  20. What javascript have you written? Are you using jQuery or vanilla javascript?
  21. I know this has been marked as solved, but just wanted to add that you don't have to go back to PHP and edit your data to get the behaviour you want. You could just do something like this: $.each(jsonData, function() { var titlePrinted = false; $.each(this, function(){ if (!titlePrinted) { //add the title titlePrinted = true; } //add the rest of the comment }); });
  22. Personally, I would use $.each() to loop through your output. Here is the code which will work: $.each(jsonData, function() { //Loop through each blog_id section $.each(this, function(){ //Loop through each comment in this blog_id output += Template.blog(this); //output the current comment }); }); example: http://jsfiddle.net/A3r7H/ Hope that helps Denno
  23. First step would be to debug whether clicking .del-action does anything. Open up the Network tab in either Chrome DevTools or Firebug (depening on the browser you're using), then click on the delete button. You should see the delete.php page show up in the network tab as soon as you press that button. The first thing I'm noticing is: $(function(){ }); inside $(document).ready(function(){ }); I'm not sure if that affects anything, or why you would need it.. Try changing your JS to: $(document).ready(function() { $(".del-action").click(function() { var commentContainer = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ type: "GET", url: "delete.php", data: string, cache: false, }); }); }); I think I've got the brackets right there.. :/ Oh and I think you should set up your data parameter in your ajax call like this data: {id: id} //don't use the string var But I may be wrong about that, it might work both ways..
  24. I'm struggling to follow exactly what you want here.. You keep saying about using a file from fork_folder if it exists, which keeps leading me back to using file_exists().. Like this: if (file_exists($fork_folder."/image.jpg")) { include/echo/return $fork_folder."/image.jpg"; } else { include/echo/return $main_folder."/image.jpg"; } If this isn't what you're after, then you'll have to try and explain the problem a bit better, because as I said, I'm struggling to follow exactly what you want..
  25. Nothing can be written better with globals. Does this mean that if main_folder() is called in a php file that is not inside a fork_folder directory, you want main_folder() to be replaced with fork_folder()? If that's the case, then you could use __DIR__ to find out the absolute path of the current PHP file, then search the path for a folder that you would expect to find in a fork_folder file, if it's not there, then that mean's you're not currently in one of the fork_folders, so switch main_folder() to fork_folder(), like: $currentDir = __DIR__; if (preg_match("/fork_folder_name/", $currentDir)) { fork_folder(); } else { main_folder(); }
  • 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.