Jump to content


Popular Content

Showing most liked content since 12/18/2017 in all areas

  1. 1 point
  2. 1 point
    The act of submitting a form is refreshing the page. If you want to do this without submitting a form you will need a Javascript program to change the document. You will need to use AJAX if you want to make permanent changes to the server in addition to changing the currently displayed page on the browser.
  3. 1 point
    You can't do that! As Cascading in Cascading Style Sheet (css) means it cascades down from parent to children or sibling to below sibling elements. it never goes up. Only with JS can that be done; The space between ':hover .text' means the element with class 'text' must be within element div with class 'buttonbottom' to cascade down to .buttonbottom:hover .text{display: none;} You can place these above .text element, adding padding-bottom:, and position: relative; to bottom of box class element to allow space for these elements, then add position: absolute; and bottom: property to these bottom buttons. this will position them to where they are now, even though they are above .test class element. Then use .buttonbottom:hover ~ .text{display: none;}
  4. 1 point
    When you use a while loop like that you cause the whole browser to freeze until all the code is finished executing. The correct way to do this is to use setTimeout() or setInterval() to send requests when needed. var characterID = "Something"; var numRequests = 30; var interval = setInterval(sendRequest, 1000); var sending = false; sendRequest(); function sendRequest() { if(!sending) { // Make sure no more than one request is happening at the same time sending = true; $.post('scripts/rcon_queue.php', {cID: characterID}, handleResponse); numRequests--; if(numRequests <= 0) { // If we've sent 30 requests then stop sending requests clearInterval(interval); interval = 0; } } } function handleRespose(response) { sending = false; if(response == "1"){ console.log("Queue is not cleared."); } else { console.log("Queue is clear."); if(interval > 0) clearInterval(interval); } }
  5. 1 point
    If you want to create classes for everything that's great, I was focused on trying to get you to separate everything in the first place. A reasonable class structure is probably the best option in nearly every situation, so if you're comfortable with that then do it. You can create, for example, a podcast class with everything you need to do with them, a podcast factory class for creating or getting individual or lists of podcasts, etc. About the code, the first thing I would do is move some of those things out into a generic include file for every page. Things like error reporting settings, database connectivity settings, and other things that are not for specific pages should go into a single include file. The point being that you only have 1 place to make changes if you need to adjust any of those. You don't want to go searching through a bunch of files if your database password changed. It looks like you need a newsletter class. Another principle of good design is that you generally want functions to do one thing. I think that function in particular would be better if it returned all of the data instead of sent everything to the browser (although it looks like you're mostly printing things just to see what's going on), because you may have a place where you want to get newsletter data but not send it to a browser. So it should return the data instead of using echo, and then whatever called the function can either load a template to print it to the browser, or maybe load an email template, or whatever else. If you broke that function above up into a class for a newsletter, it looks like some of the methods might be things like getQA, getNextPreview, getPodcasts, etc. Maybe the getPodcasts method would return an array of podcast objects that correspond with the newsletter. You would also have get/set methods for each of the database fields or other properties that make up the object (getId, getTitle, getAbstract, etc).
  6. 1 point
    Here's an example of letting JavaScript do the work for you, once you give it required minimum data. NOTE: its not a good idea to have spacing in image file names, it tends to cause problems in coding, use underscore or hyphens instead. <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" id="viewport" content="target-densitydpi=high-dpi,initial-scale=1.0" /> <title>Document Title</title> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style> .mySlides {display:none} .demo {cursor:pointer} </style> </head> <body> <table width="1000px" align="center" border="1"> <tr> <td class="style_shop_text" colspan="3"> <a href="/shop/shop_prod1_menu_1.shtml"> <img alt="Product 1" src="/images/site/shop/prod1.jpg"> </a> </td> </tr> <div class="w3-content" style="max-width:1000px"> <tr> <td style="width: 333px" valign="top"> <P class="style_shop_text"></br> Product - £11</br></br> Dimensions : 5cm (approx)</br></br> BLAH BLAH BLAH</br> </P> </td> <td valign="top" align="center" valign="top" colspan="2"> <img class="mySlides" src="/images/work/prod 1-1.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 1-2.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 1-3.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 2-1.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 2-2.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 2-3.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 3-1.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 3-2.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 3-3.jpg" width="400" height="400" alt="Product 1"> <!-- <img class="mySlides" src="/images/work/prod 4-1.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 4-2.jpg" width="400" height="400" alt="Product 1"> <img class="mySlides" src="/images/work/prod 4-3.jpg" width="400" height="400" alt="Product 1">--> </td> </tr> <tr> <td> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="xxxxxxxxxxx"> <table> <tr> <td> <input type="hidden" name="on0" value="Product_combo"> </td> </tr> <tr> <td> <select name="os0" id="Product_combo"> <option value="Product 1-1" data-src='["prod 1-1", "prod 1-2", "prod 1-3"]'>Product 1 £11.00 GBP</option> <option value="Product 1-2" data-src='["prod 2-1", "prod 2-2", "prod 2-3"]'>Product 2 £11.00 GBP</option> <option value="Product 1-3" data-src='["prod 3-1", "prod 3-2", "prod 3-3"]'>Product 3 £11.00 GBP</option> <!-- <option value="Product 1-4" data-img-index="9" data-src1="/images/work/prod 4-1.jpg" data-src2="/images/work/prod 4-2.jpg" data-src3="/images/work/prod 4-3.jpg">Product 4 £11.00 GBP</option>--> </select> </td> </tr> </table> <input type="hidden" name="currency_code" value="GBP"> <!-- <input type="image" src="http://www.mywebsite.co.uk/images/site/button_add_to.jpg" border="0" name="submit" alt="PayPal – The safer, easier way to pay online."> <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">--> </form> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" > <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="xxxxxxxxxxxxxx"> <input type="hidden" name="display" value="1"> <!-- <input type="image" src="http://www.mywebsite.co.uk/images/site/button_view_cart.jpg" border="0" name="submit" alt="View Shopping basket"> <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">--> </form> </td> <div class="w3-row-padding w3-section"> <td colspan="2" valign="top"> <table width="100%" border="0" valign="top" id="imageTable"> <tr> <div class="w3-col s4" valign="top"> <td style="width:33%" align="center"> <img class="w3-opacity w3-hover-opacity-off" id="prod_menu_image_1" height="200" src="/images/work/prod 1-1.jpg" width="200" alt="Product" onclick="currentDiv(1)"> </td> </div> <div class="w3-col s4" valign="top"> <td style="width:33%" align="center"> <img class="w3-opacity w3-hover-opacity-off" id="prod_menu_image_2" height="200" src="/images/work/prod 1-2.jpg" width="200" alt="Product" onclick="currentDiv(2)"> </td> </div> <div class="w3-col s4" valign="top"> <td style="width:33%" align="center"> <img class="w3-opacity w3-hover-opacity-off" id="prod_menu_image_3" height="200" src="/images/work/prod 1-3.jpg" width="200" alt="Product" onclick="currentDiv(3)"> </td> </div> </tr> </table> </td> </div> <tr> <td colspan="3"> </BR> </td> </tr> </div> </table> <script> $("#Product_combo").on('change', function() { parentTable = document.getElementById("imageTable"); imgTag = parentTable.getElementsByTagName('img'); dataSrcArray = JSON.parse($(this).find(":selected").attr("data-src")); $.each(imgTag, function(key) { $(this).attr('src', "/images/work/" + dataSrcArray[key] + ".jpg"); }); var myslideElem = document.getElementsByClassName("mySlides"); $.each(myslideElem, function(indexkey) { $(this).css({"display": "none"}); myslideThis = $(this); $.each(imgTag, function() { if (myslideThis.attr('src') === decodeURIComponent($(this).attr('src'))) { $(this).attr("title", indexkey + 1); $(this).attr("onclick", "currentDiv(" + (indexkey + 1) + ")"); } if (decodeURIComponent(imgTag[0].src).indexOf(myslideThis.attr('src')) !== -1) { //imgTag[0].attr('src', myslideThis.src); myslideThis.css({"display": "block"}); } }); }); }); function plusDivs(n) { showDivs(slideIndex += n); } function currentDiv(n) { showDivs(slideIndex = n); } var slideIndex = 1; showDivs(slideIndex); function showDivs(n) { var i; var x = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("product_slides"); if (n > x.length) { slideIndex = 1; } if (n < 1) { slideIndex = x.length; } for (i = 0; i < x.length; i++) { x[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots.className = dots.className.replace("w3-opacity-off", ""); } x[slideIndex - 1].style.display = "block"; dots[slideIndex - 1].className += " w3-opacity-off"; } </script> </body> </html> Now could add extra custom data for image path, or add full image file name and path, (but it looks cleaner without the path) to data-src, up to you.
  7. 1 point
    You're still doing the same thing you started with. You are not passing the function as an event handler, you are just executing it immediately when that code runs. Any time you put parentheses after a function name you are telling it to execute that function immediately. If you don't want to do that, do not put parentheses after the function name. $("#prod_menu_image_1").on("click", function() { currentDiv(imageindex1) }); $("#prod_menu_image_1").on("click", {index: imageindex1}, currentDiv); Those do slightly different things. The first one uses a closure, and every time the click event runs it executes currentDiv(imageindex1) with whatever the current value of that variable is, assuming it is available globally. The second one uses jQuery's on function to specify that an object should be available inside the click handler with a property called index that will have the value of imageindex1 when that click handler was added. That data is available on the event object according to the jQuery documentation.
  8. 1 point
    You save yourself the trouble of making an HTTP request from your server to your own server. It's like walking out the front door of your house and getting into the back door in order to go from the living room to the kitchen. In technical terms it's slow and marginally less secure. Your program should be broken into several modules, each being able to interact with each other within the same environment. You could break your program into a generate_template($vars) function and a verify_email($address, $code) function among others that do different tasks, then you would do the following: $verified = verify_email($_POST['email'], $_POST['verification_code']); if($verified) { $vars = [ 'title' => 'Something', 'name' => 'Something' ]; $to = $_POST['email']; $subject = 'Email subject'; $body = generate_template($vars); send_an_email($to, $subject, $body); } This is, of course, very simplified, but the verify_email(), generate_template(), send_an_email() functions can be used anywhere on your site, just put them in a file and include the file where needed. I usually make more complex programs and use objects with properties and methods rather than just functions. These objects can be used on many different pages, each page just has to include the objects that it needs.
  9. 1 point
    Any elements with z-index is relative to sibling element of the same level, and child elements of that element are only relative to child sibling elements of that level within that parent. A higher child z-index won't place it at a higher level than any parent sibling elements z-indexes, only the parent can do that. So a parent container is always the uppermost level to whatever its child element level is, this continues on with children elements of the child elements which is there parent and so on. NOTE: However early versions of Firefox, and maybe present version does not follow this rule completely, but you should follow this rule set up above. You have your modal position fixed using z-index: 999 within a parent element using z-index: 2; your navbar parent is using z-index: 3; like already mentioned the parent of z-index: 999, will be the highest above any children set levels, so navbar parent z-index: 3; is higher than modal parent z-index:2, so it will overlap the modal.
  10. 1 point
    The lesson you should be taking is that whenever data is being used in an environment, it should be sanitized according to the syntax of that environment. I don't know anything about hacking. I would never use the real_escape_string() function. It was used to escape string values for SQL queries before prepared statements existed. Now that prepared statements exist there is no reason to use it. I've never used filter_var() before. Some people like to use it for validating form data but there is never a situation where it is completely necessary.
  11. 1 point
    Sanitization depends entirely on how the data is being used. If it's being used inan SQL query it has to be made safe for SQL syntax, if it's being printed on an HTML page it has to be made safe for HTML syntax, if it's being put into a Javascript string you need to escape the string delimiters. The data itself, during processing, is not inherently dangerous in any way; it only becomes dangerous when it can be interpreted as code to be executed. You can't sanitize it when it comes in because you don't know where it's going to be used so you don't know how it needs to be sanitized, there's no single sanitization solution that works for all cases.
  12. 1 point
    Here's a simplified example <img src="data:image/png;base64,<?php echo base64_encode(file_get_contents("../../image.jpg")) ?>" alt=""> It's base64 encoded, the original path won't be viewable, just the encoding of image.
  13. 1 point
    An error only occurs after a statement has been executed. The error here is not a MySQL error, it's a PHP error. You can't pass one single string as multiple arguments of a function, you have to call it like this: $stmt->bind_param('ss', $clas, $sec)
  14. 1 point
    If I'm remembering correctly, setting the from header to "John Smith <system@mysite.com>" it should display that name instead of "system".
  15. 1 point
    A id identifier is singular and unique within a page, it is used to target one specific element only. A class identifier is the opposite it can be used multiple times within a page.
  16. 1 point
    The a in a:link {} represent a anchor element. What is mylink supposed to represent? class name? Then it should be .mylink:link { color: green; background-color: transparent; text-decoration: none; Else if id reference, it should be #mylink:link { color: green; background-color: transparent; text-decoration: none;
  17. 1 point
    You took away the hover class that causes the tooltip to appear. The visibility never changes.
  18. 1 point
    What doesn't work properly? Are you checking for Javascript errors in the developer console? If the CSS for that and for the other template are using the same names for classes or overwriting styles on other elements then you'll need to identify those parts and figure out how to fix it.
  19. 1 point
    Seems you are missing a double quotation there