Jump to content

Ingolme

Moderator
  • Posts

    14,890
  • Joined

  • Last visited

  • Days Won

    174

Posts posted by Ingolme

  1. Elements with "float" are ignored when calculating the height of their parent. The parent will not expand to contain these elements. Overflow forces the parent to take the floated elements into account.

    Other solutions involve adding "clear:both" to an element beneath the floated elements. This is sometimes done with the ::after pseudo-element like this:

    ul::after {
      content: "";
      display: table;
      clear: both;
    }

     

    • Thanks 1
  2. The first step is to check for errors:

    //insert details into database ........ this isnt inserting for some reason
    
    $insert = "INSERT INTO orderbook (watchid, username, symbol, timeframe, maxbid, stoploss, buyamount) VALUES ('$watchid', '$username', '$symbol', '$timeframe', '$maxbid', '$stoploss', '$amount')";
    
    $result = mysqli_query($conn, $insert);
    
    // CHECK FOR ERRORS
    if (!$result) {
      echo "Error: " . $insert . "<br>" . mysqli_error($conn);
    }

     

    Aside from that, you need to read about and use prepared statements: https://www.w3schools.com/php/php_mysql_prepared_statements.asp

    Your PHP code is vulnerable to SQL injection. If you put this on a live site it's only a matter of time before a malicious crawler arrives and starts testing your forms for vulnerabilities.They're very common, I get them on my websites all the time.

  3. You have a lot of different <head> and <body> tags. There should only be one <head> and one <body>.

    Every HTML document should have a structure similar to this:

    <!DOCTYPE html>
    <html>
      <head>
        <title>Page title</title>
        
        <!-- Metadata and stylesheets go here -->
        
      </head>
      
      <body>
        
        <!-- Text, images and other content go here -->
        
      </body>
    </html>

    All of the <style> tags must be in the <head> section, they are not allowed in the <body>.

    You have an unclosed <picture> element here. Everything beyond this point could easily just disappear depending on which browser is handling it:

    </style>
    <picture>
       <Source meida="(min-width: 300px)" srcset="images/TWP Large.webp">
       <source media
    </head>
    <body>

    There's no need to use <picture> at all, a regular <img> tag will work better.

    You should run your HTML through the validator to make sure there aren't other problems with it: https://validator.w3.org/

    • Like 1
  4. With the || operator, the loop will continue running as long as any one of the two conditions is true. The !== operators are making things look more complicate than they really are.

    I've separated the conditions from the loop to make it more clear what's happening:

    let message = prompt('Enter q or quit to quit this process!');
    
    let condition1 = message !== 'q';
    let condition2 = message !== 'quit';
    
    while (condition1 || condition2){
        // condition1 is true if the message is "quit"
        // condition2 is true if the message is "q"
        // No matter what value message has, at least one of the two conditions is true.
        // Therefore, the loop never stops.
    
        prompt('Please Enter quit or q to quit this operation!');
    }
    alert('You quit the operation!');

     

  5. The image format shouldn't make any difference to the visibility of the image.

    How are you testing this on phone and tablet? If you're copying the files onto the device, you need to make sure that the image is in the right location in the filesystem relative to the HTML file. Though I don't know if HTML documents have permission to access files. If you're not testing on an online server with a URL then for phones and tablet testing it's best to use the responsive design tools in a desktop browser instead.

    You should fix up the HTML, as some browsers might not be able to interpret it with mistakes. You need quotation marks around your style attribute. hspace and vspace are not valid HTML, you can replace it with the CSS margin property.

    <img src="images/shooting_dummy.webp" alt="Shooting Dummy" style="height:300px; width:900px; margin:7px 9px;"> 

     

  6. It looks like $class_name has all the namespaces attached. You'll have to put all the files in a folder named PhpOffice. To clean things up, you can use PhpOffice as the root of this system and not use src at all.

    The file structure will need to be something like this:

    +-PhpOffice/
      +-autoload.php
      +-PhpSpreadsheet/
        

    Then, to make sure paths are always correct, you should use the __DIR__ constant in the autoload function. If this is a linux server it would also be good to replace backslashes with forward slashes.

    <?pph
    spl_autoload_register(function ($class_name) {
        $class_name = str_replace('\\', '/', $class_name);
        include __DIR__ . '/../' . $class_name.'.php';
    });

    Then your code can include PhpOffice from anywhere.

    require('PhpOffice/autoload.php');
  7. Actually, they're not providing the autoload file. Composer generates it. Your autoload file just needs to look something like this with the right path for the folder:

    spl_autoload_register(function ($class_name) {
        include 'src/PHPSpreadsheet/' . $class_name . '.php';
    });

    The files you need to download would be these ones: https://github.com/PHPOffice/PhpSpreadsheet/tree/master/src/PhpSpreadsheet

    Put them somewhere on your server and make sure autoload has the right path for them.

  8. You just need to copy their files onto a folder your server. Then the code example they provide will work.
    The line require 'vendor/autoload.php'; will need to have the path of the autoload.php file in your server's filesystem.

     

    If you don't care about formatting or anything, you can just export your data as .csv files. It's very simple and Excel can open them. A CSV file looks like this:

    Name,Age,Occupation
    John,35,Carpenter
    Smith,28,Doctor

    A CSV file is just a file where each line is a row and commas are used to separate columns. You can build a PHP program to generate one easily. The most difficult part is escaping data. If your data has a comma, line break or quotation mark in it, it needs to be escaped. Data is escaped by wrapping it in quotes and quotation marks themselves need to be escaped by duplicating them. Here's a simple function to escape data for use in a csv file:

    function csv_escape($str) {
      // Line breaks, commas and quotation marks must be wrapped in quotation marks
      if(
        stripos($str, "\r") !== false ||
        stripos($str, "\n") !== false ||
        stripos($str, '"') !== false ||
        stripos($str, ',') !== false
      ) {
        // Replace " with ""
        $str = str_replace('"', '""', $str);
        // Wrap string in quotation marks
        $str = '"' . $str . '"';
      }
      return $str;
    }

     

  9. The include is the one causing the problem.

    The element which is sticky needs to be a direct child of the body element. The code will need to look something like this:

    <style>
      .sticky {
        position: sticky;
        top: 0;
        left: 0;
        width: 100%;
      }
      .w3-top {
        position: static;
      }
    </style>
    
    <body class="w3-content" style="max-width:auto">
      <div class="sticky" w3-include-html="/Nav-Test.html"></div>

     

  10. You can have a script which runs periodically to update the height of open panels to fit their content. Something like this might work.

    setInterval(updatePanels, 1000);
    function updatePanels() {
      let activePanels = document.querySelectorAll(".accordion.active + .panel");
      activePanels.forEach(panel => {
        let maxHeight = parseInt(panel.style.maxHeight);
        if(maxHeight != panel.scrollHeight) {
        	panel.style.maxHeight = panel.scrollHeight + "px";
        }
      });
    }

     

  11. If you copy and paste code without understanding how it works then mistakes are inevitable and you won't be able to identify them. You need to first learn the basics of Javascript before trying to build complex things.

    I recommend reading the Javascript tutorial [ https://www.w3schools.com/js/default.asp ] and doing all the exercises and try-it examples along the way. Once you have done that you should be able to make these games work without a problem.

  12. The ability to solve problems is essential to being a developer, this is what I am trying to teach.

    1. Always have the browser console open. When the page loads, look at the error messages. Each error message will tell you exactly what and where the problem is. If you don't understand what the error message means, I can explain it to you so that you will understand other error messages like that in the future.

    2. Interpreting your own code. You should read your own code, line by line, and write down on paper what value every variable has at each point in time. This is called "tracing" and all developers need to know this. Here's an example of a trace for a small block of code.

    1  let sum = 0;
    2  for(let i = 0; i < 5; i++) {
    3   sum += i;
    4  }
    5  console.log(sum);

    Trace
    You have to read through the code and write something like this down on paper. If you can't do this, you cannot write software.

    Line number Variables Code
    sum i
    1 0 undefined let sum = 0
    2 0 1 for(let i = 0; i < 5; i++ ) {
    3 1 1 sum += i
    4 1 2 }
    2 1 2  for(let i = 0; i < 5; i++ ) {
    3 3 2 sum += i 
    4 3 3 }
    2 3 3  for(let i = 0; i < 5; i++ ) {
    3 6 3 sum += i
    4 6 4 }
    2 6 4  for(let i = 0; i < 5; i++ ) {
    3 10 4 sum += i 
    4 10 5 }
    5 10 undefined  console.log(sum)
  13. There is not enough information here to solve the problem, so I have to make some guesses.

    It's possible that the fade class has an animation which makes the slide fade out. Try removing the fade class from the slides. If you want a fading effect, the Javascript code needs to have some control over it.

×
×
  • Create New...