Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 05/24/2018 in all areas

  1. 2 points
    The purpose of an object template, such as "Person" is for organizing code. In any part of your software, if you are given an object of type Person you know for sure that you can find a name and age property on it. If the object has no type then you don't know what properties it might have. You would use an object template if your software uses the same kind of object a lot. If you're only using the object in one place then you can use the shorthand {} to define it.
  2. 1 point
    No. UPDATE is what you use to start an UPDATE query when you are updating the table. It is not a command on its own. You might be thinking of commit, but you only need to commit if you're using transactions, which it doesn't look like you are. When you insert a record outside of a transaction there's nothing else you need to do to actually insert the record, just the insert query will do it. My condolences.
  3. 1 point
    The first thing you need to do is check that the values in the session are actually set, like their user ID or whatever you're tracking. Once you figure out who the user is, that's authentication. Then, you need to figure out if they have permission to do whatever they're trying to do, that's authorization. There are a variety of ways you can track permissions like that depending on what your needs are. In general, if someone fails authentication or authorization they are usually redirected to a login page or something with an error message.
  4. 1 point
    You might want to take a look at the contents of the $result variable. If the content you're getting from the curl requests is already JSON encoded you actually have to decode them before adding them to the array.
  5. 1 point
    Don't do anything in the browser, anybody can hack that. All session information should remain on the server side. You do have to check the $_SESSION variable on every page where the user needs to be logged in.
  6. 1 point
    if ($method_name[] == '_get') { That's your syntax error. You really need to set this up so it's writing to an error log. Using commands to set those options at runtime instead of setting them in the config file means that if you have a syntax error, it will not use any of your error settings because it never even starts executing the code to set those options. $method_name = filter_var($_POST['methodName'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); $_POST['methodName'] is an array, not a string. You're probably setting $method_name to the string "Array" since filter_var will convert values to strings before sanitizing. That's not an "even if", that's a requirement. Otherwise you're outputting one block of text after the other with no way to know where one ends and the other starts. The most obvious way is probably to return an array or object with all of the values in it. If you don't care about separating the two, then yeah you can just dump everything out. json_encode
  7. 1 point
    You should never use position: for website layout, especially absolute or fixed. instead of using img tag use background-image: instead, then you can use background-position: background-size: auto 100%; to get all the features you just mentioned.
  8. 1 point
    You need to process both, and return data from both as a single encoded JSON format .
  9. 1 point
    It doesn't work like that because you're not doing anything with the object the function returns. You could. var obj = outerFunction(); obj.kir();
  10. 1 point
    If that is controlled by .htaccess then it's dependent on the location of that file. Files in different directories may behave differently if the rules in .htaccess say that.
  11. 1 point
  12. 1 point
    The answer given on StackOverflow will update the data structure, but it will not be saved to a file. The data disappears as soon as the user leaves the page. There is no way for Javascript to write to a file. You have to use a server-side program to write to the file for you. Javascript can send the data to the server, but the server has to write the data to the file.
  13. 1 point
    It doesn't mean anything in any languages I know.
  14. 1 point
    Then use the actual same URL, not a URL with a bunch of line breaks in it. I'm not sure what you expect to happen when you have a bunch of line breaks in a URL, but I bet it's not what's actually happening.
  15. 1 point
    In the loop, the variable $row is an associative array that contains all the values that you need. The $row variable works exactly the same as it does in this example: https://www.w3schools.com/php/showphpfile.asp?filename=demo_db_select_oo For the LIMIT part, it doesn't matter if you're using PDO or anything else, you just need to put the two numbers in the query. You can have two variables: $offset and $limit and then set the query to be "LIMIT $offset, $limit". Make sure that $offset and $limit are both forced to be integers or you'll be facing the problem of SQL injection again.
  16. 1 point
    I made a mistake, the fetch() method is called on the statement itself while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  17. 1 point
    First, you have to use prepared statements to send data to your queries. If you don't it's highly likely that some unexpected data will cause errors in your query and break your program and in the worst case scenario this can be used to hack your website. You can use the IN() operator to compare a field to multiple values. This works best in PDO, where you can pass parameters as arrays: <?php $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // Set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Build a string of placeholders like ?,?,?,?, one for each array element. $amount = count($uniqueValueArray_id); $placeholders = array_fill(0, $amount, '?'); $search = implode(',', $placeholders); // Prepare the statement $limit = 5; // Make absolutely sure this value is an integer or the program will break $stmt = $conn->prepare("SELECT id, text, date, FROM text WHERE id IN ($search) ORDER BY id DESC LIMIT $limit"); // Run the statement, passing in the values $result = $stmt->execute($uniqueValueArray_id); while($row = $result->fetch(PDO::FETCH_ASSOC)) { // Display the result here however you want print_r($row); }
  18. 1 point
    About CSS and rule precedence CSS is currently the best system we have for easily creating flexible layouts. Some people might hate CSS but I'd like to see if they can come up with a better alternative. CSS rules are chosen based on how specific the selectors are. In general the following rules apply: A rule with an ID selector always has precedence over a rule without one. A more specific rule has precedence over a less specific one, that is when the selector has more pieces in it. If two rules are still the same after the previous tests, the last rule has precedence. This works across stylesheets and in the document as well. To get more details you can read this article: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity The solution to your specific issue The issue here does not seem to be with precedence, though, it's actually a combination of a lot of small things. First, due to browsers very unusual way to render fieldsets, you need to set the min-width of your fieldsets to make them behave like normal boxes: #yp_container fieldset { min-width: 0; } The second thing is that you have to restrict your box's width so that the text is not given the opportunity to not wrap. If it's allowed to stretch the box, it will do that instead of wrapping, so we'll set the max-width of the box to 100%. #current_referral_url { max-width: 100%; } Finally, you made a mistake: The overflow-wrap property should be set to break-word. The normal behaviour is to not break. #current_referral_url { max-width: 100%; overflow-wrap: break-word; } A word about using IDs as selectors I would recommend not using IDs in your selectors if you have any other option. IDs are very powerful and as you know, with great power comes great responsibility. When you use an ID selector to set the style of an element, you make it terribly difficult for rules anywhere else to override your style. If you are going to use an ID selector, you should be sure to use it to only set properties that are very special to the element, which in most cases none of them are that special. It's a good idea to make all your selectors as weak as possible, you never know when you want to override them. A word about usability in your website I haven't had a good moment to tell you this, but your website has a severe usability problem and you have already been experiencing its negative effects. Every time you want somebody to get to a specific page on your site, you find yourself forced to give a long list of instructions on how to get there. This is a problem, there should be unique URLs to get people to land on any part of the site in just one click.
  19. 1 point
    Most browsers will show a collapsible representation of a data structure of you log it using console.log().
  20. 1 point
    The computer doesn't care how many items are there, the only thing that matters is whether it follows the correct format. There are all kinds of text editors that will let you collapse whatever part of the structure you want. The built-in developer tools in the browser will do that also if you print the structure to the console. There sure is, and the browser does all of that automatically. I have never written code to parse a JSON structure, there's no reason to write that when it's a format the browser understands natively. JSON is native Javascript, it stands for Javascript Object Notation. The browser already understands it, you don't have to parse anything like that yourself. Yep. var obj = JSON.parse(json_str); console.log(obj);
  21. 1 point
    <!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> </head> <body> <div id="demo"></div> <script> Number.prototype.pad = function(size) { var s = String(this); while (s.length < (size || 2)) { s = "0" + s; } return s; } var demoDiv = document.getElementById("demo"); demoDiv.innerHTML += "<p>" + (2).pad(3) + "</p>"; // => "002" demoDiv.innerHTML += "<p>" + (10).pad(3) + "</p>" // => "010" demoDiv.innerHTML += "<p>" + (100).pad(3) + "</p>" // => "100" </script> </body> </html>
  22. 1 point
    Its just a matter identifying object, transverse down to parent item, object/array using dot.notation and looping through each child item to display its value. <!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 src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> <script> visitor_data = { "lastVisits": [ { "firstVisit": { "prettyDate": "Monday, May 14, 2018", "otherItem": "recent" } }, { "firstVisit": { "prettyDate": "Monday, May 14, 2020", "otherItem": "in future" } }, { "firstVisit": { "prettyDate": "Monday, July 04, 1900", "otherItem": "WAY Way in the past" } } ] }; $(function() { for (x in visitor_data.lastVisits) { var para = document.createElement("p"); var paraText = document.createTextNode(visitor_data.lastVisits[x].firstVisit.prettyDate + " : " + visitor_data.lastVisits[x].firstVisit.otherItem); para.appendChild(paraText); document.body.appendChild(para); } }); </script> </head> <body> </body> </html>
  23. 1 point
    LastVisits within JSON object is not defined correctly visitor_data = {"lastVisits": [{"firstVisit": {"prettyDate": "Monday, May 14, 2018"}}]}; visitor_data.lastVisits[0].firstVisit.prettyDate;
  24. 1 point
    My first guess would be that what you have is just a string instead of a JSON object. Log the full object into the console to see what it contains.
  25. 0 points
    Here's an idea, Try it!
×