Jump to content

maxxd

Gurus
  • Posts

    1,657
  • Joined

  • Last visited

  • Days Won

    51

Posts posted by maxxd

  1. I'm a huge fan of soft-delete, personally. IMO the only time data should be completely and actually deleted is in the case of a GDPR request or some other situation where you can face legal action for not deleting the information completely. I've even seen setups where the user's data is replaced by basically a hash - the record still exists, any foreign records still exist and link back to the original record, but the personal data has been scrambled or blinded in some way that makes it basically useless to anyone who can view it.

  2. First and foremost, I hope this code isn't on a live server - you're wide open to SQL injection in many, many places.

    That having been said, there's also some suspect logic - for instance, line 186. Even if it were working I'm not sure you'd be getting the results you expect. Right before that, you set $stok_awal to the value of $data['qty'] or 0 if $data['qty'] is null. You then subtract $data['qty'] from $stok_awal (which again, is the value of $data['qty'] or 0) without checking to make sure that $data['qty'] exists.

    The basic problem here is that $data['qty'] doesn't exist. Or more to the point, $data is null. You need to output $data and see what exactly - if anything - it contains.

    After that, look into prepared statements and update all your queries.

    • Great Answer 1
  3. What error did you notice in your index.php file? Assuming the 'It has this in it,' is a copy/paste error and not actually in that php file, it looks fine (best practice is to leave off the closing php tag, but I don't think that has any bearing on your current issue).

    Please excuse me if this is a dumb question, but your comment about the error in Apache's log and mac_guyver's excellent point about the OS injecting file extensions got me thinking a couple things. You've tested that Apache itself is working, yeah? Like, you get the welcome page on a fresh site setup? Also, the page you're trying to serve via Apache has a '.php' extension? If you put the following code into the file 'testing.php' and the visit 'http://{yourdomain}/testing.php' you see 'Hello World!', right?

    <?php
    echo '<p>Hello World!</p>';

     

  4. OK, if there's no `mysqli` section in the output from phpinfo() then it's not enabled. Check your C:\PHP8\php.ini file and make sure the line `extension=mysqli.dll` doesn't have a semi-colon in front of it. Restart IIS and if that doesn't do it, then I'm sorry but somebody with more hands-on experience than I is gonna have to step in.

  5. I haven't run PHP on windows in literally a decade or longer, so I'm not sure how much help I'm going to be. Do you have a section labeled 'mysqli` in the output from `phpinfo()`? You mention in your first post that you've updated C:\PHP8\ext, but your phpinfo is showing the config as C:\PHP8\php.ini - I know in Ubuntu there's an entire folder full of extension files - mine is at `/etc/php/8.0/mods-available` and includes files like `mysqli.ini`.

    As a bit of an aside, is this for production or development? If you're looking at a development setup on a windows machine I highly recommend either using WSL or Docker - preferably Docker, but it's not always an option (I'm typing this on my Surface tablet that can't handle Docker so I use local installs in WSL for dev).

  6. Definitely check phpinfo() as mac_guyer recommended. Sometimes PHP uses an unexpected configuration file - check for both the Loaded Configuration File value and make sure that there's a full mysqli section in the output.

    Also, save yourself a ton of pain and switch to PDO now - it's much easier to deal with than mysqli overall.

    • Great Answer 1
  7. 5 hours ago, richarddunnebsc said:

    Why is data undefined after

    I agree with and you should heed both benananmen and gizmola's points. But for your specific question here looks - as ginerjm points to - like a question of scope. For instance, as you (I assume) learned fixing the database connection, you couldn't use $user or $pass variables within the __construct() method because you didn't pass those variables to the __construct() method. Every variable, method, and function (with some limited and typically ill-advised exceptions) has a scope outside of which it doesn't exist. So, look at where you define $data - is it in the same scope as where you use $data? Was it in the same function, or was it passed to the function that's trying to use it?

  8. That's kind of just a wall of poorly formatted code, so it's hard to tell where the actual problem is but let us see the GetPosts() method. What you're describing should be a data gathering concern, not a display concern.

    Other unsolicited advice - your entire comment output should be a method of it's own; right now the two blocks are almost identical. And I'm assuming the poor formatting is due to copy/paste issues, but on the off chance that it's not then fix that as it'll make reading your code much easier.

  9. You can't make it work without altering the code you already have. Your code doesn't take pagination into account, so in order to use pagination you must alter your code.

    You'll need to add a LIMIT clause to your query, then add links that target the same page with an updated starting record ID. When your page is loaded, check to see if that start number is set - if it is, it becomes the new starting offset in your SQL limit clause. If it doesn't exist, the starting offset is 0.

    That should be enough to put you on the right path - give it a shot and if it doesn't work post your code here with your questions.

  10. In addition to the box model, there's semantic web markup wherein the tags define the structure of the page and how important individual elements are - this is important in many different ways to many users. I think this is what everybody so far has been getting at - note that Barand used a span with the class 'headline' instead of an actual h1 tag and requinix pointed out that headings and paragraphs aren't meant to be displayed inline. It's based on the box-model structure that gizmola linked to and (i believe) informs the standard coding practices that Strider64 is talking about. This is by no means a complete explanation of the concept, but it's a decent place to start - https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Document_and_website_structure.

  11. It could just be nested indexed arrays. So instead of

    foreach($employees as $employee)
    {
        echo "Name: {$employee['name']}<br>";
        echo "Department: {$employee['department']}<br>";
        echo "Salary: {$employee['salary']}<br>";
    }

    it would simply be

    foreach($employees as $employee)
    {
        echo "Name: {$employee[0]}<br>";
        echo "Department: {$employee[1]}<br>";
        echo "Salary: {$employee[2]}<br>";
    }

    Not the best pattern or most readable code, but if it's early days in the class it could get a lesson about array access across.

    Edit: this is assuming the array declaration in the initial comment is from the instructor as the system input.

  12. Not sure what's the best place for this, so mods please feel free to move it somewhere more appropriate.

    I'm having literally no luck forwarding the SSH agent from my host machine to my docker images. I'm trying to set up an image that can use composer to pull several private bitbucket repositories.

    My docker-compose file includes a composer:2 service, shares volumes with my main app service, sets an environment variable SSH_AUTH_SOCK to /ssh-auth.sock, and mounts that volume to /ssh-auth.sock in the built container. No dice.

    After several days of not being able to do it via docker-compose I copied and pasted the exact code from the official docker Composer image:

    eval $(ssh-agent); \
      docker run --rm --interactive --tty \
      --volume $PWD:/app \
      --volume $SSH_AUTH_SOCK:/ssh-auth.sock \
      --env SSH_AUTH_SOCK=/ssh-auth.sock \
      composer install

    and tried it without docker-compose; I got the same please make sure you have access to your private bitbucket repository error as I get in my compose file.

    I know this can work, but every example of it working doesn't actually work in my case so I assume I'm missing something...

    Anybody have any ideas or advice?

×
×
  • 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.