Jump to content
Pardon our ads (a necessary update) ×

gizmola

Administrators
  • Posts

    6,167
  • Joined

  • Last visited

  • Days Won

    165

Posts posted by gizmola

  1. On 12/2/2025 at 7:45 AM, Psycho said:

    I agree 100% with @requinix about setting the type of the field to a numeric input. However, I am a belt and suspenders type of programmer. UI constraints are great for helping the user to avoid common data entry errors, but I believe all such validations should have server-side controls (what if the user POSTed a form outside the UI?).

    Right.  It's an annoying issue with web development, but user input can never be trusted, and input validation must always be placed in both places.

    My approach has long been to start with the backend and insure that you are validating raw submission.  This is where tools like postman are helpful.    Once the backend is locked down, you can then move to validation in the HTML and javascript.  You can get by without validation or HTML5 forms in the front end, but you can't get by without the backend validation.

  2. This comes down to some basic advice, particularly where databases are concerned (assuming you are using a sql database):

    • Always use the right datatype.  Money is a particular problem for floats, so depending on the database, you can either hack the use of an integer or if there's a datatype like the mysql DECIMAL type, something already designed to handle money without the potential for rounding errors.
    • This also should tell you, that to support flexibility, your database should also include an indicator of the "type" of currency.  If you implement a type table, your application will be able to know the difference between an amount that is stored in pounds or euros, or US dollars.  
    • Once you realize that floating point datatypes aren't good for handling calculations involving money, you then want to look into possible approaches.    Even if you are using a DECIMAL field in the database, that doesn't insulate you from rounding errors if you read the values into PHP Floats and start doing calculations with those values.

    This is a few years old, but I think it's a good starting point for considering how your code works now, and potential ways to address currency and calculations that involve currency.

    In general, the display of data formatted in a way that is standard for an end user is referred to as "locale" and when you setup a personal workstation or server, you are asked questions that then configure the OS, typically using locale specific standards.  So the presentation of a "currency" number and the actual currency that number represents should be a presentation issue.  Unless you have a system that is actually storing values in multiple currencies (which would then add an entire extra layer of complexity that's probably beyond the scope of what you are currently working on), you should not be accepting strings that may or may not include a currency character, and then trying to manipulate them.  That is all presentation logic, that should be separate, and essentially invisible to the inner workings of your application.  

    Don't accept character fields in your form, and this problem goes away.  If you want to add some intrinsic UI functionality that allows you to cut/paste a value, handle that in javascript and just strip out any non numeric characters.

     

  3. These models describe how the relational database engine handles concurrency.  You don't DO anything.  The Database does things for you, using various algorithms and whatever concurrency model you've configured it to use.  These differ from RDBMS to RDBMS.

    This particular optimization is intended to deal with the processing of timestamped transactions in a transaction log that is being used to actually write out data.   

    So by definition, this involves multiple "user/connections" that are trying to operate on the same row of data at close to/near the same time so that the transaction log is likely to have these read/write pairs of operations that could end up being in conflict with each other , and those scenarios are specific to an application and typically few/far between.  

    In your case, for a banking transaction where you might need to debit/credit, you would wrap the changes inside a transaction, perhaps having issued a SELECT FOR UPDATE if the transaction would be updating a balance field.  

    I'm not sure what the value of focusing on Minutiae like this provides, without any practical application or testing on your part.  To examine how this all works, and what ramifications it would have, you would need to:

    • Have a database that implements the Thomas's write rule
    • Set up a database/tables
    • Simulate the different scenarios (which is non-trivial as these would need to be separate sessions)

     

  4. 7 hours ago, maxxd said:

    I've not tried it, but I've heard things about https://nativephp.com/docs/mobile/1/getting-started/introduction so that may be worth looking into. I agree with gizmola that your preference for procedural code is probably going to be difficult.

    Certainly interesting project, but from what I've seen, very new and more like a proof of concept at present, rather than a legitimate contender in the cross platform mobile space.  The mobile is also inherently closed source and requires a license, which is not the case for the many alternatives discussed.  I mean you can develop cross platform mobile apps with commercial game development platforms like unity as well, but I didn't mention those.   I don't object to the nativephp folks trying to build a business around their mobile platform, but the closed source nature of that makes this an apples/oranges comparison to the other options I listed.   

  5. This is a large topic to cover.

    To start with, you can (and should) have been practicing "responsive" web UI development.    So there's that option.

    Given you aren't interested in native development, you should look into cross platform mobile development options, which include:

    • React Native (Typescript/Javascript)
    • Flutter (Dart)
    • Xamarin (.net/c#)
    • Ionic (javascript/css/html)

     

    There are numerous other options which are less popular, but might be a better fit for you.   Literally everything is going to be at very least object based, so your desire to avoid OOP is going to be problematic for you, although it is always possible to write essentially procedural code even though you have an object based framework.  Your familiarity and use of javascript is one of the areas you need to explore, should you want to use React Native or several of these other web tech oriented bridge technologies.  There's also overhead involved in certain frameworks where the app utilizes a built in javascript runtime, rather than strictly relying on the compilation process to produce native apps for your targets.

    Other options:

    • Apache Cordova (Ionic built on top of it, so few would choose Cordova directly these days, for various reasons)
    • Nativescript (javascript/html/css).  Competes with Ionic, and depending on the app, might be better at delivering native mobile OS features
    • Kotlin Multiplatform (Kotlin). This an interesting option you should look into.  Kotlin was created by Jetbrains, which is the company best known for its editor tools, and in the php world, the generally acknowledged "best" IDE PHPStorm. 

    You might be wondering about how this all came to be, but it makes more sense if you know a bit about the history of Java and Android.  The official development language of Android initially was Java, and you created native Android apps using Java.  Jetbrains IDE products are written in Java, and that began with what was their flagship editor IntelliJ Idea.  So they have a long history as being a key technology company in the java development community.  Kotlin was created to sort of be for Android, what Swift was for IOS -- an alternative to a more verbose, lower level language like Objective C or Java.  

    The main advantage is that by learning Kotlin you are learning the recommended native Android development language, while also being able to create native IOS applications with Multiplatform.  It's also a language that I think might accommodate your desire to write mostly procedural code.  

  6. I only scanned your project but I have a few questions I'd like to see answered:

    • Why would someone want to use your library when there are libraries like Guzzle or Symfony's HTTP Client that do the same thing?
    • I didn't see any unit tests.  Are you planning to add those?  I think that's pretty much a requirement these days if you want people to adopt and have confidence using a new library.
  7. Quick additional comment.  The result of fork is a new process, which I'm sure is clear.

    What you might be missing is that the child process is identical to the parent at the moment of the fork call.

    At that point you now have 2 identical processes that are proceeding from the point of the fork call, because they share the same call stack. 

     I converted your pseudo code into a small c program and compiled on my mac.  As the windows OS doesn't have fork and in general is entirely different this code would have to be compiled and run in WSL or a VM under windows

     

    #include <stdio.h>
    #include <unistd.h> // For fork
    
    int main() {
        int a = 50;
    
        if (fork() == 0) {
            a += 5;     
        } else {
            a -= 5;
        }
        printf("Value of a: %d\n", a);
        return 0;
    }

     

     

    compile it and run: 

    clang fork.c -o fork
    ./fork

    Output:

    Value of a: 45
    Value of a: 55

    At least under osx, it seems that the child process runs and exits first, although the underlying management of memory is left to the OS. 

    It is likely that child processes will run first, because of the way memory is handled by the OS.  Fork wants to copy the memory space of the parent to the child, but the OS wants to defer that and uses "Copy on Write".  If it ends up being a situation where nothing in the child process differs, the OS doesn't need to copy memory, so the OS will likely opt to have the child process run before the parent process, but there's no strict rule or definition or relationship with fork, that requires one process to run before the other.  

  8. 12 hours ago, phppup said:

    I'm trying to understand async, I promise, but it seems like a slick fakeout.

    Am I missing something.

    PS: I've seen numerous examples that say the same thing, so I'm really looking for an honest human opinion.

    Javascript allows for asynchronous functions. 

    To understand how JS works in the browser there are some educational resources like this one, that help illustrate things that aren't easily understood just by looking at js code.  While a highly watched video when released, if you do watch it, just keep in mind that it was created prior to ES6 was fully released and supported by the major browser engines.

    There are now a few visualizers like this one:  https://www.jsv9000.app/ you can use to step through code.  

    The Javascript engine allows for asynchronous functions through its implementation of a "Task Queue".  

    Prior to ES6, asynchronous calls required callback functions.  The use of many nested/interwoven asynchronous functions with various callback functions can be highly confusing, and for people used to procedural programming, it lead to confusion and a proliferation of functions often referred to as "callback" hell.

    • Promises were introduced with ES6 as a way of organizing Async calls. "A Promise is an object representing the eventual completion or failure of an asynchronous operation."
    • Along with support for promises, the javascript engines added a 2nd queue: the MicroTask queue.
    • In particular, Promises were created to better support chaining asynchronous functions together, as in many situations, you want a series of functions to run, any of which can return out of order, and still be able to chain those results together in the order required.  This comes up frequently when using external API's where there are a number of different calls being made within any specific area of code.
    • I would just be regurgitating what is on this page to elaborate much further:  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises

    For some people, the look of a series of chained Promises, each of which returns additional promise objects looks less procedural than they would like, particularly when there are chained async calls that need to be resolved in order.  For that reason, ES7 included the async and await keywords and syntax.  

    It's your choice as to whether you want to use async/await or just stick with promises, although there are some things that promises can do that are not as easily done (or perhaps done at all) just using async/await syntax.  

    Again, I would defer to the explanation on MDN, and that page in general for more explanation and examples, as it begins with:
     

    Quote

     

    The async function declaration creates a binding of a new async function to a given name. The await keyword is permitted within the function body, enabling asynchronous, promise-based behavior to be written in a cleaner style and avoiding the need to explicitly configure promise chains.

    You can also define async functions using the async function expression.

     

  9. Here's an overview, including debugging:

     

    Once you open the devtools view, "console" is one of the tabs.  Any javascript errors will be displayed there, so that's a good first thing to check.

    In your js code you can do this as an alternative to what you were doing:

    document.addEventListener('DOMContentLoaded', () => {
      const applyBtn = document.getElementById('bulkApplyBtn');
      if (applyBtn) {
        console.log(' Button found!');
        applyBtn.addEventListener('click', onApplyBulk);
      } else {
        console.log('⚠️ applyBulkBtn not found in DOM.');
      }
    });

    With your dev tools open, and the console tab selected, you'll see those log statements when the page runs.  For situations like this you probably want to open the dev tools view, and then reload the page, so it reinitializes.  FIrefox and Safari have developer tools with these same features, but there are often small differences, and a learning curve that goes into whichever you choose to work with, but you don't have to use Chrome.

  10. Probably because something IS different between the two scenarios, despite your belief that they are exactly the same.

    The only other thing that occurs to me to question, is whether or not you have cached versions of any of the included scripts.  It's important when debugging javascript scripts to insure you've cleared your cache.  Shifting into Incognito Mode, installing a browser extension, and validating the code you are actually testing are all techniques that can help, but it is a pervasive problem that confounds even experienced developers at times, and is a challenge for deployment strategies.

    We don't have your code, we don't know what the specific issues are, and we can't debug it for you.

    To reiterate, you have access to the tools you need to answer this question, built right into your browser.  

    Your other option would be to reproduce all the code in snippets, with the hope that someone here would take the time to do the analysis and debugging needed to pinpoint what issues are coming up, but I'd rather teach you to fish.

  11. Not really, no.

    It is likely a scope issue, or a situation where intialization is being done, and a secondary file is redeclaring a variable or changing an event handler.  

    This is where the Web developer tools (console, js debugger) should be the first thing you investigate. 

    One other thing to mention is that there are many tools used by js/web developers like webpack or node libraries people use to combine js and css files, and minify/add definitions to make your code work better across browser platforms, and allow the use of typescript or sass/scss etc. You might want to look into those tools, as combining multiple js files into one "combined" file is one of the most used features.

  12. We appreciate your update.   There are many long time contributors like Mac and Psycho who visit the site regularly, and when someone like yourself improves their understanding and manages to build something that solves a problem for them, that makes us really happy. 

    One never knows for sure which threads prove to have long term worth, but various topics have been picked up by search engines and the site sees a substantial amount of traffic to some of them, so there could easily be people in the future who you end up helping because their questions are similar to yours.  PHPFreaks is one of a very few remaining sites 100% run by volunteers, which for many of us, is our way of contributing back to the PHP Community that provides the language, libraries, and tools many of us use professionally. 

    With AI taking the place for many of what search engines used to provide, along with developer communities like Stackoverflow and phpfreaks, many of the developer specific communities have been closing up, and Reddit has a lot of mindshare especially with younger developers.

    PHPFreaks gets a fraction of the number of members and posts we used to see a decade ago.   Since PHPFreaks was always run by the community, we've continued on when many other communities closed.  New PHP developers with questions like yours are the reason the site continues on, and is a nice reminder of why we help keep it running.     

    • Like 1
  13. 1 hour ago, veewee7764 said:

    I would use a Raspberry Pi for this.

     

    If you look at his last message, he stated he has a pi and is using it already.  I believe he had been able to send signals to the hot tub controller using a serial connection, but was having problems making a bi-directional connection using fopen.  There were a few different suggestions provided, but I am not sure where it stands.  Would love to see where the OP got to with the project.  PHP usually isn't used for this type of application. 

    Your system sounds really interesting.  I'm sure many of us would be interested to hear more about why you built it.  Is this all internals for a custom designed vending machine, or is this a front end for a kiosk or small store area with a variety of machines?  Really curious what the application is, and what problems you were solving.

  14. 1 hour ago, veewee7764 said:

    Awesome. . . Now I just have to go learn how to make that field a decimal, not a character!

    That is what I needed!

    That's one of the great things about SQL is that you have declarative syntax.  So you just issue an "ALTER TABLE MODIFY COLUMN ..." statement and it will be fixed.  Depending on the implementation it will often convert existing data, although sometimes that won't work.

    A good way to test this sort of statement out in advance is to make a copy of the original table, which is also really easy in SQL:  "CREATE TABLE t_example as SELECT * FROM example".

    This will make an exact copy of the table structure and data, although indexes and constraints aren't copied, but for testing an ALTER statement it works great.  It's also a quick and dirty way of having a backup of the data in a table when running any sort of large update you want to do interactively.  

    Then you can run your ALTER statement on the t_example table to test it out first, and see if there are any warnings or syntax problems.

    If you are REALLY careful, you can get the same sort of protection using transactions, but if you don't recognize a mistake, once you commit there's no way to recover the data you might have changed or removed.

  15. It doesn't matter how many times we have explained the same thing.  The op doesn't incorporate any of the information that has been provided.  

    I explained in detail previously that this was incorrect:

    $username=$_POST['username'];
    $password=$_POST['password'];
    if (isset($username, $password)) {
    if ($_POST['submit']) {

     

    And this is incorrect.

    $register->bind_param("ss", $username, $hashadPonny);
    $register->execute();
    
    
    if ($register) { .... }

     

    I gave OP code snippets to address these problems, which were not used. 

    They also refuse to indent their code, which I assume is because they are just iteratively adding the code they got from chatgpt back into chatgpt over and over again, hoping it will fix code they don't understand.

    I'm not sure if it's the language barrier or what exactly, but there is no learning going on.  It's the same lack of understanding as before, and essentially the same question, with some minor modifications to the code that doesn't fix what isn't working.

  16. A couple of things to note about whatever application it is:  

    It used the Smarty Template Engine.  Smarty was at one time, a very influential library.  It works by performing a "compilation" step where the smarty template files are "compiled" into pure php scripts that are then used at runtime.  

    PHP now has two competing MVC frameworks that have pushed use of the language forward, those being Symfony and Laravel.  Each has its own Template system:  Twig for Symfony and Blade for Laravel.  They also perform this compilation step.  While great for it's time, you don't see Smarty used much anymore, as people can use Twig, or use pure PHP templates that intermingle HTML and PHP, and don't require a complicated compilation system.

    As for the deprecation, the "join" function is an alias for "implode".  In other words, there are two names for the same function.  Implode tends to be the name used by most PHP developers, as it's the inverse of the well known php function "explode". 

     

    <?php
    
    $fruit = 'Pear,Banana,Cantaloup,Grape,Apple';
    var_dump($fruit);
    // string(33) "Pear,Banana,Cantaloup,Grape,Apple"
    
    $fruits = explode(',', $fruit);
    
    $originalFruits = $fruits;
    // sort is a function that "mutates" the $fruits array by sorting it
    sort($fruits);
    var_dump($fruits);
    /*
     array(5) {
      [0]=>
      string(5) "Apple"
      [1]=>
      string(6) "Banana"
      [2]=>
      string(9) "Cantaloup"
      [3]=>
      string(5) "Grape"
      [4]=>
      string(4) "Pear"
    }
    */
    
    $fruit = implode(',', $fruits);
    var_dump($fruit);
    // string(33) "Apple,Banana,Cantaloup,Grape,Pear"
    
    //See if there is any difference in the number 
    var_dump($originalFruits);
    
    $diff = array_diff($fruits, $originalFruits);
    // Event though the order of elements changed, there are the same elements in both arrays, so the diff of the arrays is empty
    var_dump($diff);
    
    // Output
    string(33) "Pear,Banana,Cantaloup,Grape,Apple"
    array(5) {
      [0]=>
      string(5) "Apple"
      [1]=>
      string(6) "Banana"
      [2]=>
      string(9) "Cantaloup"
      [3]=>
      string(5) "Grape"
      [4]=>
      string(4) "Pear"
    }
    string(33) "Apple,Banana,Cantaloup,Grape,Pear"
    array(5) {
      [0]=>
      string(4) "Pear"
      [1]=>
      string(6) "Banana"
      [2]=>
      string(9) "Cantaloup"
      [3]=>
      string(5) "Grape"
      [4]=>
      string(5) "Apple"
    }
    array(0) {
    }

     

    When PHP evolved, an important philosophy was that it was eagerly extended using it's C API.  There has long been numerous libraries written in C, and many PHP contributors set about to write extensions so that those libraries could be used within PHP.  There weren't strict standards or conventions in place as to the recommended way that parameter lists should be implemented, and different developers had different ideas about what makes sense.  People with an axe to grind have criticized PHP for this, but in most cases, they entirely seem to have missed the fact that libraries created to extend the language were not part of the core.

    Even with that caveat in mind, implode and explode are unusual, in that they allowed you to provide the primary parameters in different orders.    I guess they finally decided to remove this option, while at the same time adding the "named arguments" feature which provides an alternative method of providing arguments to functions in any order you want, if that is desired.  I think this was inspired by languages like Python that have a similar feature, which in my opinion has limited uses.  The main place where I could see some value in the use of named arguments is in the case of a function having multiple parameters with default values.  The only way you can intermix the use of order parameters and named arguments is when you provide a named argument at the end of an argument list.  

    So the one place that named arguments provides something new is in the case where you have a function with a number of required arguements followed by a number of "optional" parameters which were defined to have default values.  Prior to this feature, if you had 2 or more "optional" parameters defined in the function signature, you could not provide an argument to the 2nd -> n parameters, without also providing arguments for the other optional parameters.  

    With this named argument feature, you can now just pass a named argument for defaults you want to override.  Having functions with a laundry list of parameters is an anti-pattern, so I don't see this as being a huge improvement to the language, but perhaps others might disagree with me.

     

    function test($foo, $bar, $baz='bz', $raz ='rz') {
        echo "$foo $bar $baz $raz" . PHP_EOL;
    }
    
    $f = 'Foo';
    $b = 'Bar';
    $raz = 'Raz';
    
    // Now able to skip over the need for 'baz' parameter, and just pass optional 'raz'
    test($f, $b, raz: $raz);
    
    // Output since PHP 8, wasn't available in 7.x
    // Foo Bar bz Raz

     

    • Great Answer 1
  17. 8 minutes ago, polaryeti said:

    I am using postgres if that helps.

    Yes.  I would start here:  https://www.postgresql.org/docs/online-resources/

    In particular go through one or more of these:

    The main reason you might want to do one vs. the others, is that the 2nd tutorial has a test system built into it, and the 3rd is entirely online.  

    If you haven't already done so, I'd recommend setting up a test/learning postgresql instance, either in the cloud, or locally.  Docker is a great tool for this.  With databases you just want to be make sure you understand how to create docker volumes, since you want your postgresql instance to store data in a docker volume.

    This is a solid free introduction course on Youtube:  

     

     

    If you want to opt instead for a Book, these come highly recommended from the Postgresql community:

     

    https://theartofpostgresql.com/

    One issue with books on relational databases is that things change over time, and books can age poorly.   The newest version of Postgresql (18) was released a bit less than a month ago, so there aren't a lot of books out that cover it's latest features, but there is at least this one to consider:

    https://www.packtpub.com/en-us/product/postgresql-18-for-developers-9781806028474

     

     

     

     

  18. 16 hours ago, FarsHatt said:

    That was not the answer I was looking for

    Can you elaborate? 

    mac_guyver gave you an outline of standard best processes and concerns.

    I rewrote your code to make it more sensible, which you I guess are not using or learning from.  For example, you want to know if your query execution was successful.  I showed this in the code I provided:

    $executed = $_mysql->execute();
    
    if ($executed && $_mysql->affected_rows === 1) {
        $_success="Konto skapat successivt!";
        echo $_success;
    }

     

    Now you are back to trying to use a mysqli statement object like it was a boolean, which is incorrect.  

     

    It looks like you're just generating broken code with AI.  I asked you to indent your code, and you aren't indenting it. 

    $register= $_POST['username'] /* THIS IS THE PROBLEM AREA */ $_POST['password'] ?? $conn->prepare("INSERT INTO users (username, password, CREATED_AT) VALUES (?, ?, now())");

    Of course you are having problems with this, because it doesn't make any sense.  It is an attempt to use the "Null coalescing" operator which is in no way appropriate here.

    We have no idea WHY you are writing code.  Is this for a registration page?  If so, you don't just take username/password pairs and create a new database record every time.  The code is missing the typical step of checking to see that the username does not already exist.

    If you want to continue to just Vibe code, and go backwards in the process, this is a waste of time for all of us.  One things that AI tools are great at, is taking code you don't understand and getting it to explain the code to you.  Perhaps you should do that.

  19. I would say the consensus is, and most people who learned SQL with relational databases will tell you that it's best to combine your fundamentals with exercises or experiments with an actual relational database.

    SQL is declarative, so for some people that is something they haven't experienced previously. 

    A relational database is a tool.  So the question to ask yourself, is "why learn SQL?"   Furthermore, each relational database is an implementation, which often will include extensions, specialized datatypes, different types of indexes and storage engines, etc. which you aren't going to find in Codd's papers.  

    So I'd have to say, you are approaching this in the opposite direction from what most people would.  Most people get access to a database, start creating a database or using a sample database, and use a client or tool to execute queries.  

    For most developers, they are trying to persist application data, answer questions, create reports, visualize data, etc. and those requirements will then drive the need to understand how SQL statements can support those needs.  Once you have the basics down, you might want to go deeper.

    I would compare this process to that of learning any modern programming language.  I'll use PHP as an example:  you learn PHP syntax (and for many that is all they want or need to know about it, in order to use it to solve problems).  PHP is interpreted and has a virtual machine that compiles source into "opcodes" which the virtual machine actual executes, so it's possible to explore PHP internals for a deeper understanding of PHP.  PHP itself, if written in the C language.  So you can learn C.  C is a compiled languages, so you can learn more about C compilation and machine language.  Ultimately there are different operating systems, and these operating systems can run on different architectures -- and so on, down the rabbit hole as far as you may want to go.

    If however, people expected that they needed to understand from the ground up, how everything works at the most fundamental level first, then nearly everyone would experience analysis paralysis and never make it to the point of actually being able to create systems, write software and solve problems.  

    I also like to try and understand the fundamentals of technology, but that is an imperfect process and one that can be a supplement to building things using what you know, and figuring out how to solve your problems along the way.

  20. Why are you not indenting your code blocks?  It makes reading code confusing and error prone.

    Honestly, I am not sure I understand your question, but I can see some things that make no sense.

     

    <?php
    $_username=$_POST['_username'];
    $_password=$_POST['_password'];
    if (isset($_username, $_password)) {
        if ($_POST['submit']) {
            $_hashadPonny = password_hash($_password, PASSWORD_ARGON2ID);
            for ($i = 1; $i <= 1; ++$i) {
                $_mysql=$conn->prepare("INSERT INTO _users (_username, _password) VALUES (?, ?)");
                $_mysql->bind_param("ss", $_username, $_hashadPonny);
                $_mysql->execute();
            }
    
            if ($_mysql) { # Alla tre # Here is my problem
                $_success="Konto skapat successivt!";
                echo $_success;
            }
        }
    } 
    ?>

     

    So a few things:

    1.  $_username=$_POST['_username'] is being assigned outside the test to see if the the form was submitted.  The point of using isset() is to protect from the assignment using a variable that doesn't exist, and $_POST['_username'] will not exist unless the form was posted.  

    A more standard way of checking that a script was called via a POST request:

    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit']) {
        if (!empty($_POST['_username'] && !empty($_POST['_password']) {
            $_username = $_POST['_username'];
            $_password = $_POST['_password'];
            // Insert this user
        }  
    }

     

    Following this code you have a for() loop for no reason.  Remove that.  To determine if an INSERT, UPDATE or DELETE actually worked, you can check both the result from the ->execute() method as well as the value in ->affected_rows.

    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit']) {
        if (!empty($_POST['_username'] && !empty($_POST['_password']) {
            $_username = $_POST['_username'];
            $_password = $_POST['_password'];  
    
            // Insert this user
    
            $_mysql=$conn->prepare("INSERT INTO _users (_username, _password) VALUES (?, ?)");
            $_mysql->bind_param("ss", $_username, $_hashadPonny);
            $executed = $_mysql->execute();
    
    
            if ($executed && $_mysql->affected_rows === 1) {
                $_success="Konto skapat successivt!";
                echo $_success;
            }
        }
    }

     

     

  21. Often these types of questions are vague and missing in information in order to see if you have an understanding of K3s.  

    A much more direct and useful question would be:  "Are you familiar with K3s, and why would you use it instead of a K8 implementation?"

    At that point, you'd want to be able to talk about why K3 was created, how it differs from K8 implementations, and where you might use it or not.  

    Answers to those questions are summarized very well here:  https://traefik.io/glossary/k3s-explained

    K3 was a project from Rancher Labs, which was acquired by SUSE, so check out https://www.rancher.com/ if you want to find more resources for K3s and see how it fits into the Rancher suite of products.

  22. 9 minutes ago, mike3075 said:

    mac_guyer-

    Thank you for the quick response!  I tried your suggestion.  For this example lets says the ccalid = 442

    <div class='ccalbox ccalcourt-textarea'><textarea class='ccalcourt-somebad'   name='court[{$data['ccalid']}]'>" .$data['ccalcourt'].   "</textarea></div>
    <div class='ccalbox ccalcourt-textarea'><textarea class='ccaljudge-somebad'   name='judge[{$data['ccalid']}]'>" .$data['ccaljudge'].   "</textarea></div>
    <div class='ccalbox ccalcourt-textarea'><textarea class='ccaladdress-somebad' name=address[{$data['ccalid']}]>" .$data['ccaladdress']. "</textarea></div>
    <div class='ccalbox ccalcourt-textarea'><textarea class='ccalphone-somebad'   name=phone[{$data['ccalid']}]  >" .$data['ccalphone'].   "</textarea></div>
    <div class='ccalbox ccalcourt-textarea'><textarea class='ccalfax-somebad'     name=fax[{$data['ccalid']}]    >" .$data['ccalfax'].     "</textarea></div>
    <div class='ccalbox ccalcourt-textarea'><textarea class='ccalnotes-somebad'   name=notes[{$data['ccalid']}]  >" .$data['ccalnotes'].   "</textarea></div>

    Then run this code when the Submit button is pressed:

    Shouldn't it return:

    POST Form Field Names:

    court442

    judge442

    address442

    phone442

    fax442

    notes442

    submit442

     

    You seem to be missing the point on html array syntax which you should use to replace your attempt to force some dynamic set of html markup.

    <div class="ccalbox ccalcourt-textarea"><textarea class="ccalcourt-somebad" name="court[]"><?= $data['ccalcourt'] ?></textarea></div>

    When submitted, $_POST['court'] will be an array.  Typically, if you are designing something to be dynamic, you would create some javascript code that adds new elements based on however you want the user to interact with it.  It could be as simple as a button that says "Add New" and you would then add the html element:

    <div class="ccalbox ccalcourt-textarea"><textarea class="ccalcourt-somebad" name="court[]"></textarea></div>

     

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