Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. gizmola's post in Setting up an account on Web app was marked as the answer   
    In general, this would be called provisioning. 
    For the most part, this requires that your application have an underlying architecture that supports this.
    In terms of DNS, you can set up a wildcard DNS entry for *.myapp.com.
    Internally, your application needs code that accepts a request, examines the requested url, extracts the subdomain, and executes the routing accordingly, or you can also have a rewrite that will look for subdomains other than 'www' and rewrite those to https://myapp.com/shop1.
    When a new user creates a store, you will run provisioning code in your application that does any required setup (make new database user, create database with new user assigned rights, save credentials in user profile configuration file or in database.)  There are strengths and weaknesses to each approach so you have to consider the tradeoffs and security implications of each approach.  For example, you could just use the primary database access user, and not create a separate database user for each customer database.  There isn't one right answer for each application.  
  2. gizmola's post in Oracle SQL certification path? was marked as the answer   
    Oracle database has been around a long time, and has a lot of features and extensions that are specific to it.  If you are not going to use it immediately, or need a certification for a job, I wouldn't recommend going down that rabbit hole, even though I do think that Oracle database is a great RDBMS in many ways, but it is commercial and expensive.  You often see it paired with java/enterprise java applications.  For reasons I won't go into, besides cost, very few people pair PHP with Oracle database.   The open source database closest in design and features to Oracle is Postgresql, so if anything, exploring postgresql would be a step in that direction.
    Since you use SQL Server, I would suggest getting certs in that, and in particular, learn about the specific things you listed, like transactions and concurrency (locking), and Views, stored procedures and triggers.  Sprocs and Triggers are very important and highly used in SQL server development (Transact-SQL aka T-SQL), and in Oracle (which has an entirely different stored procedure language).  MySQL also has stored procedures & triggers, but they are not commonly used, in comparison to the way that they are very often baked into applications that use sql server on the backend, as is the case with a lot of .NET applications.
    I don't think you can really say you are confident in your SQL knowledge until you are confident in the many ways you can use joins (including self joins), and the use of grouping and aggregation, as these are some of the primary reasons people use relational databases.  It also helps to learn about the way rdbms's work in terms of datatypes, constraints and indexes.  You want to have a good working understanding of the different types of indexes and the ways they overlap with primary key/unique constraints.  You also really need to understand concurrency and locking, as it pertains to each database, and an understanding of transactions as well as "2 phase commit" support.  
    While all the major relational database engines have configuration options that can be used to alter the concurrency/locking models, MySQL (and forks like MariaDB)  is particularly different in that it allows for the use of different engines.  For example, the original MySQL engine (myisam) is very different from the popular InnoDB engine that most companies use.  It's a simple example, but MyISAM has no support for transactions, so you can write code that starts transactions and commits or does a rollback, and mysql will happily except that code, when in fact it actually ignores those statements entirely and doesn't support transactions whatsoever.  
    You also want to understand how you install and configure these databases, and what options and tradeoffs might be involved in how you set them up.  This affects how a database might/might not recover from a crash/ lose some data/transactions (or not), have backup options, or support replication in various flavors.   With the existence of Docker, it's now much easier to experiment and learn about these databases, and create local test configurations.  
    I think it helps to keep in mind, that there are categories of developers (DB Architects & Administrators & DB developers) who specialize in these products, and they have extensive levels of depth to them.  There are some well known experts with books you might be interested in.  A couple off the top of my head, are Joe Celko, who wrote some well known SQL books, and Tom Kyte, who authored many books on Oracle, and was well known for his "Ask Tom" column where he answered oracle questions and demonstrated ways certain problems could be solved.
    PHPFreaks is fortunate to have a number of developers who have consistently shared their expertise with relational database design and SQL, so this is still a great place to get advice and in many cases example code.
  3. gizmola's post in query not working as expected was marked as the answer   
    It would not work any better in Oracle, because your logic is faulty.
    Keep in mind that inside your parens, if any of those items are TRUE, then the entire group is true.
    team_name is not null or team_name !='' or team_name NOT LIKE '%[teamname]%') In the row you don't expect, consider each condition
    team_name is not null ---> true
    team_name !='' ---> true
    team_name NOT LIKE '....'  ---> false.
    So you get the row, despite the fact that the 3rd condition is false.  What it appears you really want is:
    team_name is not null AND team_name !='' AND team_name NOT LIKE '%[teamname]%')  
  4. gizmola's post in What is the purpose of the begin and end ^ and $ characters, when should I use them and what do they do? was marked as the answer   
    If you are looking for -- exactly, a line that starts ... then has something you want to match, followed exactly by the end of a line, then you may want to use those anchors.  
    Regex is integrated into a lot of different languages and subsystems, for a number of different purposes.  For example, it might be that your use case is to find, within a bunch of lines of text, a particular pattern like a phone number or a url.  
    Another use case, might be entirely different, as in the case of a password which must meet certain criteria.  In the case of a password, you would want an exact match, including the start and end anchors, whereas, if you're looking for a phone number or a url within a bunch of other text (perhaps in a forum like this one) then you certainly would not want the match to only be made including the start and end line anchors.  
    In some subsystems (apache mod_rewrite for example) the context of the data available to be evaluated with regex, already assumes start and end anchors, and actually trying to apply them won't work, so that might lead to some confusion, when rewrites don't work the way you expect.
  5. gizmola's post in Why can't I GROUP BY emp_name only in this query? But why am I able to GROUP BY orderid alone? was marked as the answer   
    The column(s) you select will generate one row(group) per unique value of that column.  
    Simple example of orders, assuming the order contained a column for the country_code of the customer that placed the order.
    You want a result with the "Total value of orders by country".
    So you would want to GROUP BY country_code.  
    Your result set will then have 1 row for each country, but a SUM(amount), of course will provide you the total value of orders for that country. 
    Let's say instead, you want a sum of orders by country, but you want the total for that country by year.  
    SELECT country_code, YEAR(order_date) as year, SUM(amount) FROM ORDERS GROUP BY country_code, YEAR(order_date) ORDER BY country_code, year At that point you're going to get a row for every country_code/year combination, and the SUM(amount) is relative to that grouping.
  6. gizmola's post in Understanding subqueries! was marked as the answer   
    Simple subquery article:  https://www.guru99.com/sub-queries.html
    A subquery is exactly what the name describes:  An inner (sub) query that is run, with a result that is then used by an outer query.  It is not complicated.
    In order for it to be used in a "WHERE column =" the subquery must return at most 1 value.  If it can return multiple rows/values, then you need to use  "where column IN" or possibly NOT IN.
    My 1st tip:  a subquery can't possibly work as a subquery, if it doesn't run by itself in standalone fashion.  You want to investigate, whether or not you can use a HAVING clause without a GROUP BY.
  7. gizmola's post in PHP Statement and PHP Script was marked as the answer   
    Strider64 pretty much explained it.
    A php script gets executed, but typically has many statements.
    A single statement is a line of code that gets executed.  Typically, you know something is a statement when it requires a semi-colon at the end of the line.
    <?php $counter = 0; // Statement echo 'Values' . PHP_EOL; // Statement for ($x=0; $x < 10; $x++) { // Multiple initialization statements in the for construct $counter = $x + 1; // Statement echo "$counter. Value of x = $x" . PHP_EOL; // Statement } // { } denotes blocks, which contain statements but strictly speaking are not statements themselves  
  8. gizmola's post in Loading Youtube video in Magnific pop up window was marked as the answer   
    Yes you are missing something obviously different, which is that you are including jquery and the magnific popup code in the wrong order AND loading it in the body rather than the head section.  Try changing it to this:
    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> Document </title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> <script src="jquery.magnific-popup.js"></script> <link rel="stylesheet" href="magnific-popup.css"> <script> $(document).ready(function() { $('.popup-youtube').magnificPopup({ type: 'iframe' }); }); </script> </head> <body> <div> <a class="popup-youtube" href="https://www.youtube.com/watch?v=Euy4Yu6B3nU">Air</a> </div> </body> </html>  
  9. gizmola's post in rating system was marked as the answer   
    So what people are trying to say is that something must run the submit_rating.php when a review is posted.   The same script needs to be run when a page is loaded, as it returns the data you need for your page to update the numbers you want to see updated in a json structure.
    We can surmise that the way to do the ajax calls is with jquery, since jquery was included in the html you provided.
    Here is the jquery documentation.  Read through that and try and adapt their examples.  Just to simplify things for you you can focus on the $.ajax() method, as the other methods are just HTTP request type wrappers around $.ajax.
    The html page you provided needs some jquery code to:
    define the handler code you need that will submit the form data to submit_rating.php bind that handler to the submit button of the form define a function that takes the json results returned from submit_rating.php (which are the actual stored ratings) and using those to update the various places in the Dom where the relevant numbers are required.  Doing that can also be done with jquery, which has various methods to select and then manipulate DOM elements. Currently there is no code to do these things, that you have presented.  If you need to write that code yourself, then you now have a basic step by step guide as to what you need to do.  It's also a pretty standard way of doing things, although jquery has fallen out of favor in recent years as javascript frameworks like vue and react have become popular.  Neither of those frameworks are relevant to your code though.
    I will mention in closing, that it would be very helpful for you to understand submit_rating and it's dual purpose.  That script is designed both to update the statistics if the review form was submitted, and to also get the statistics, and those 2 functions are not mutually exclusive.  You must understand how to construct a POST structure in your function that is meant to handle a form submission, by getting the input from the field(s) needed and passing that in the post.  Make sure you understand how to get that code to be triggered when the form is submitted, and not triggered when it's not needed (ie when it's just a GET request to load the page).  
    Hope this helps you move forward.
  10. gizmola's post in Error message copying data from one database to another on the same server was marked as the answer   
    You are clearly new to doing queries with the php mysqli extension.
    First of all, why are you including extraneous parens and punctuation in your query?
    What you are doing:
    $sql= "select * from cic_remus.contacts where (id='$id');"; What it should be:
    $sql = "select * from cic_remus.contacts where id=$id"; Your problem is likely a logic issue as Kicken has pointed out, but you should also address the underlying issue for debugging purposes:
    This is telling you that you have an uncaught exception, so try surround the code with a try..catch block for that and then display the actual exception message and query next time you do this.
    try{ // sql query code } catch(Exception $e) { echo "Error: " . $e->getMessage(); }  
    I'm not sure why you are doing what you are doing, when instead you can just do a query:
    INSERT INTO cic_kenobi.contacts AS select * from cic_remus.contacts ON DUPLICATE KEY IGNORE If the tables don't exactly match (you can craft the individual values statement in the same way you already have been).  You can run this from PHP but unless you are doing this frequently, having it scripted within php doesn't have a lot of value to it.
  11. gizmola's post in how to add extension in php? was marked as the answer   
    I don't know what you found on SO, but it's unrelated to the intl extension.
    What operating system are you running? What version of php? How is your development environment configured? Are you using Docker?  
    Note: The library you are trying to use states that it is "depreciated"  (sic).  It was also forked by the originator to a different repo, with the intention of passing it on to other maintainers.
    Since you are using Laravel, this one might be a better fit for your project:  https://github.com/TechTailor/Laravel-Binance-Api
    It states it is still in alpha, but depending on what you intend to do it might be a better fit for you.
  12. gizmola's post in Meta data programmatically was marked as the answer   
    Search engines just look at the final http response data.  They have no visibility into the internals of how a page is rendered.
    There is no problem doing what you want to do, and in fact many cms's, forums and frameworks do this exact thing.
    Just to be clear, meta tag keywords are ignored by google, so you may or may not want to include those in your page rendering.
  13. gizmola's post in Adding a count to a basic player with mysql and php was marked as the answer   
    Yes, so implementing kicken's suggestion, this should work probably:
    $('audio').on("play", function(){ let requestSent = [] return function(){ let a_id = $(this).attr("id") if (requestSent.includes(a_id)) { return; } requestSent.push(a_id) $.ajax({ url: "count-play.php?id=" + a_id , success: function(result){ $("."+ a_id + "count").html(result) } }); }; }()); Hopefully you understand what this code does, which makes use of some tricky javascript concepts, namely:
    Javascript closure An IFFE
  14. gizmola's post in PHP coded button was marked as the answer   
    There's a lot to work through here, so I'll start with this:
    With CSS, always start with more general rules, then more specific ones.  You have multiple embedded style blocks here, and I'm not sure why, but your general rules were added after the specific ones Keep in mind that styles "cascade" per the name. You don't need to re-declare all the attributes for a modification.  Just use a modification class Many popular css frameworks like tailwind depend on this idea   Getting familiar with a naming convention for css like BEM will help you create clear and logical css class names and avoid pitfalls and making your css inconsistent spaghetti It also will help you keep things clear.  Use camel case for your PHP variables, and for class naming and general code formatting and style start with PSR-1 and perhaps graduate to PSR-12 It might not seem that important to you starting out, but it will help you get the most out of whatever editor/IDE you are using Most people are using either PHPStorm (the choice of most pro's) or Visual Studio code with the Inteliphense plugin installed If you go with vscode/Inteliphense make sure to read the installation instructions carefully and disable the built in plugin as directed Take a look at my changes to your css and html markup to see how I implemented these ideas on your code You rarely will want or need to use css id rules.   ID's are reserved for a single instance on an page.  For buttons, you are typically re-using those styles throughout the page, so use css classes for those and not id's Most css pros rarely/never use #name css styles.  If this is tutorial type stuff, might tell you something about the freshness of the tutorial PHP code runs on/in the PHP server.  It does not run in the browser like javascript code that is included or embedded in the html page. In other words, your PHP code will be run in response to a request, and returned immediately. You can intermix html and PHP blocks inside a php script, and that will work fine, but the PHP code needs to be in a PHP block, which starts with <?php  As you should be able to see here, you have commented out all the PHP code you wrote using html comments.  Thus none of that is going to run. There is an alternate syntax that can be used to make everything look a bit cleaner if you plan to do a lot of intermixing You can look up those options in the PHP manual.  It allows shorthand for echo, and if - then -else type constructs and other PHP loop For superglobal array variable or array keys (or any other variable that may or may not exist) you want to check before blindly trying to utilize it.  There are various language helpers that you can use to get around the situation where a variable doesn't exist. isset empty() function null coalescing operator Take care with PHP blocks inside if-then or if-then-else constructs.  In general, it's a good idea to always make sure you have a block { ... } to handle each case.   Your blocks don't look correct. Try not to chain if-then else, when instead you can use multiple if blocks.  The code is easier to read and update in most cases.    
    The issue with the code presented is that you have buttons but no form, so this invokes a lot of confusing default behavior and questions you might want to ask yourself like:
    Why/where is the form submitted? What type of submission is it? For example, if the type of submission is not a POST, can you expect $_POST variables to exist?  
    I don't address these questions for you, but I expect you will need to figure them out soon.
    Here's some modifications to your code illustrating these thoughts:
    <meta charset="utf-8"> <title>Work intergrated learning</title> <style> body { font-size: 30px; } p { font-size: x-large; } .btn { padding: 10px; font-size: 20px; border-radius: 10px; font-weight: bolder; transition: background-color 2s ease Os; cursor: pointer; } .btn--submit { background-color: red; } .btn--submit:hover { background-color: green; } .btn--cancel { background-color: yellow; } .btn--cancel:hover{ background-color: orange; } </style> Rest of code...
    <p>Creating a button</p> <br> <?php if (isset($_POST['btn-atc'])){ echo 'You have added an item to your shopping chart'; } ?> <input type="submit" name="btn-atc" value="Add to Cart"> <?php $btnSubmit = isset($_POST['btn-submit']); if ($btnSubmit) { echo 'Your query has been successfully submited, our consultant will get in touch with you as soon as possible'; } $btnCancel = isset($_POST['btn-cancel']); if $btnCancel { echo 'You have cancelled your query.'; } ?> <input type="submit" name="btn-submit" class="btn btn--submit" value="Submit query"><br> <input type="submit" name="btn-cancel" class="btn btn--cancel" value="Cancel">  
  15. gizmola's post in how to properly store an ip address? was marked as the answer   
    I'm guessing something like this might work for you (assuming you have a reverse proxy or load balancer).
    protected function getClientIP() { // This assumes a classic AWS Load Balancer is proxying if (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && !filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { $ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); return $ip[0]; } else { return $_SERVER['REMOTE_ADDR']; } }  
  16. gizmola's post in How do I think about recursion? was marked as the answer   
    I should probably add that the secret to determining if recursion allows for something elegant, is to determine if you can reduce the problem down to a discrete examination.  In the case of my solution, the insight I depend upon is that I only need to check the outer 2 letter of the string in order to determine if it *might* be a palindrome. 
    Another solution using this insight could also be coded using map and reduce. 
    It also needs to be said that the overhead of recursion means that it is almost never employed, although there are some problems involving nested arrays where I see people using it in PHP.  
  17. gizmola's post in [docker] error_log() not work was marked as the answer   
    The PHP process may not be able to write to the /var/log directory.  Assuming it's the apache user that php is running as in this case.  Connect to the container and check out the perms for /var/log.  
  18. gizmola's post in How to Push an Empty Array into an Object was marked as the answer   
    And everything I wrote previously still applies.
    let json_array = {} json_array.excludes = [] // Use array method json_array.excludes.push("a") json_array.excludes.push("b") //array syntax json_array["excludes"].push("c") console.log(json_array)  
    I Updated the codepen as well with this example code.
  19. gizmola's post in Wordpress cross-plugin refering was marked as the answer   
    My educated guess is that requinix is right.   I also think the code snippets reflect that the order object should be available in plugin2 via $this->object.
    So I would suggest you try adding this code to plugin2
    $this->placeholders['{order_service_time}'] = get_post_meta( $this->object->get_id(), '_wfs_service_time', true);
  20. gizmola's post in database error connection issues was marked as the answer   
    Did you look at the contents of your wp-config.php file?   The database settings should be found right at the top of the file.  Are they there?  Did they get changed or blanked out?  You need to verify that you can connect using the host/username/password/database combination.
  21. gizmola's post in using array_diff on 2 arrays was marked as the answer   
    He literally gave you code that works, only missing a semicolon:
    $result = array_udiff($table, $newdata, fn($a, $b) => $a <=> $b); var_dump($result); If you are familiar with Javascript ES6, it is a similar type of anonymous function shorthand, equivalent to this:
    $result = array_udiff($table, $newdata, function($a, $b) { return $a <=> $b; }); You need to have a current supported PHP version ( >= 7.4) although the syntax I showed works with any version 7.x or >
    The "arrow function" version was introduced with php 7.4
  22. gizmola's post in When user tries to download .iso, tar.gz, or .deb from my website php is opening the file instead of downloading it was marked as the answer   
    One pro tip:
    Never have a php end tag (ie. ?> ) in your scripts.  It is not needed, and can lead to bugs like this  remove all php end tags whenever they are the last thing in a .php file.
    You can start with looking at PSR-1, and perhaps graduate to PSR-12 if you are looking for some standards to help guide you.
  23. gizmola's post in Cant find the old thread about wrapper/container (CSS2-3). was marked as the answer   
    I don't have any specific recollection of such a thing, but a lot of things have changed in the css world, most notably the standardization of flexbox and grid that make older techniques and tricks of css layout obsolete.  You just don't need those things anymore when flexbox or grid can take care of your layout needs with simple, consistent and easy to understand syntax.  
    There was a time when you needed to know the ins and outs of floats and clear fix, and other arcane tricks of css, but that's basically obsolete knowledge.  People also use to use tables inside tables inside tables to get their "pixel perfect" layouts, but that also has given way to a focus on creating layouts that adapt from desktop to mobile.  
    This guy (Kevin Powell) has become well known in the css/web design world, and he really knows his stuff.  This video covers flexbox.  If you work through the examples with him, you will learn what you need.  He also has a corresponding Grid video.
    If you want something more interactive, lots of people love Scrimba, and in particular Per Borgen, who is one of the Scrimba founders.  He happens to have a free scrimba course covering grid and flexbox, so that is another way you can learn flexbox, if you want something more interactive.  The free Scrimba Grid/Flexbox course is here:   https://scrimba.com/learn/cssgrid
  24. gizmola's post in How to override trait methods from another trait? was marked as the answer   
    In the PHP manual section Traits section.
    You have 2 options:
    Alias the conflicting method so it doesn't conflict Specify an "insteadof" method statement in the use section of the class
  25. gizmola's post in PHP Variable Variables & Loops with Forms was marked as the answer   
    No worries - we all agree on using PDO so that is a good investment of your time.
    If you want to goto a new page that just has the signup form, then have all the buttons in the game list inside anchor tags.  Then you can just pass the game_name as a url parameter to the page that generates the form.  The signup page can just set the hidden game attribute using the $_GET parameter.
    I personally would opt for the usability of not having a separate signup form, but if it's simpler for you to go from a->b->c and get things working that way, do that then.  It makes the javascript event stuff simpler, although you will definitely need to learn that sooner than later.  I like Scrimba as a platform to learn html/css/javascript concepts, although there are many other freemium platforms.  Freecodecamp also does a good job.
    Simpler solution for you, again rendered buttons inside your foreach loop that lists the games (ie. one button per game listed):
    echo "<a href='signup.php?game_name=\"{$game['game_name']}\"'><button class='btn_game_signup'>Signup for this game</button></a>"; Clicking on the signup page will send a GET request to your signup.php script, which will include the $_GET parameter of 'game_name'.
    Then you just set the hidden form attribute of that page in your signup.php script to the value of $_GET['game_name'].
  • 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.