Jump to content

gizmola

Administrators
  • Posts

    5,229
  • Joined

  • Last visited

  • Days Won

    76

Community Answers

  1. gizmola's post in No data supplied for parameters in prepared statement was marked as the answer   
    Obviously if you don't have all the data required for the insert, you are going to get an error. One issue that you have made for yourself unnecessarily is:
     
    $user_id=""; $date_created = date( 'Y-m-d H:i:s' ); $date_edited =""; So i'm going to assume that you have an auto_increment for user_id, and date_edited can be null, and since this is a new row you want that to be NULL on insert.

    In this case, you should not be passing values for these. MySQL figures out how to auto_increment, and it makes no sense to pass a NULL date string for a date parameter that you will never set in this context.


    Change the insert so that those are not included:
     
    $stmt = $connection->prepare("INSERT INTO users values(?,?,?,?,?,?)"); $stmt->bind_param("s,s,s,s,s,s", $firstname, $lastname, $username, $hashed_password, $date_created, $status_id);
  2. gizmola's post in Call variable from another function in class was marked as the answer   
    When you define your class, just have properties that store the values you need to ingest from the constructor. Typically you want these properties to be private or protected, so scope them accordingly.
     
     
     

    class Client { private $currentAccount = 0; private $numberOfAccounts = 0; public function __construct($start = []) { //code $this->currentAccount = $currentAccount; //more code $this->numberOfAccounts = $numberOfAccounts; } } It looks like you would benefit from a quick read through the PHP manual section that covers classes and OOP
  3. gizmola's post in Importing an .xlsx file to a MySQL Database by using phpMyAdmin was marked as the answer   
    You can certainly convert it from Excel to csv easily enough, but you need csv to import, so if you can have that instead it saves you some complications.  The important thing with csv is that your string columns need to be surrounded by double quotes so that commas inside a string don't confuse the parsing. This also necessitates that if you have double quotes in the string, the double quotes have to be doubled in order to escape them.
     
    Excel export to csv should do this for you, so ultimately it's up to you if the excel has value outside of the import, or if getting a .csv version is more trouble than it's worth.
  4. gizmola's post in Always Incorrect Credentials when logging in was marked as the answer   
    I'm afraid you need to actual read/debug/trace the login code in order to understand why it works with the original table and not yours, but at least you have pinpointed a logical place to start.
  5. gizmola's post in set partial text color via javascript was marked as the answer   
    You can't just randomly color a piece of text. What you can do however, is put a span around that section, and style the span.
  6. gizmola's post in Real time order confirmation was marked as the answer   
    There aren't any generic examples out there to look at.  The closest thing I could suggest to you would be to look at the php ecommerce projects like Magento, Opencart and WooCommerce (for Wordpress) and even perhaps the API documentation for Shopify.
     
    It depends 100% on a companies specific payment processing & fulfillment systems.  
     
    In the US, there is consumer law that regulates things like this, in terms of consumer goods and when you are actually allowed to charge someone for a product, but even if we ignore that, the simple fact is that companies often have fulfillment and accounting systems that need to be integrated with, or there is no reason for a system to wait.  What is it waiting for?
     
    -Was there inventory available, and could that inventory be reserved?
    -Did the payment go through
    -Alert the fulfillment system that the order was successful, so that the order can be fulfilled
     
    In other words, there is no generic solution to the problem anyone can point you to.  
  7. gizmola's post in Building a CMS was marked as the answer   
    There is no magic to it, it's javascript/ajax.
     
    With that said, in the last few years, javascript frameworks have developed a tremendous amount of momentum.  Essentially this moves a lot of the code from the backend into a client javascript application.  Typically the backend becomes an api providing access to data via REST or SOAP.  I don't see a lot of people using SOAP anymore.
     
    Wordpress has been all in on the use of ReactJS, even to the extent that they announced they would abandon its use due to Facebook's plan to utilize a BSD + Patents license.  Ultimately, Facebook bowed to the pressure and threats to abandon it and changed the ReactJS license to MIT.
     
    At any rate ReactJS, Angular, Ember, Vue etc. are all quite prevalent in the current web development world, and provide the sexy interactive UI you are talking about.  The underlying technology that anchors all of these technologies is still Javascript/Ecmascript and Ajax which facilitates actively changing the UI without having to GET/POST the entire page and rebuild it from scratch.
  8. gizmola's post in Proper place to put memcache caching was marked as the answer   
    One of the reasons to do dependency injection in your use case is to de-couple the specifics of caching from the specifics of the switch. Memcache is not the only caching technology out there, so you could improve the reusability and utility of the class by utilizing an interface and wrapping the memcache in a class that implements the interface.
     
    You also have the option of doing setter injection rather than injecting memcache in the constructor. Again, that is something that makes things more optional.
     
    Whether any of this effort is beneficial in your specific situation is up to you. If you're not planning to change code inside the Switch class, it hardly seems worth the effort, although there shouldn't be much of a noticeable difference when you pass a memcache object into the Switch class as a parameter. A fundamental change from 3.x to 5.x was PHP passing all objects by reference, thus eliminating a common reason people used Global objects in the olden days.
  9. gizmola's post in aws elastic beanstalk permissions and ownership. was marked as the answer   
    You are running shell scripts that set environment variables for some reason. Maybe these are ubuntu things, but they aren't important to the basic workings of the system unless there is something happening in the apache startup script. I personally use amazon linux for all my ec2 instances, since they insure it works well with ec2 and they come preconfigured with package repos maintained and tested by amazon.
     
    At any rate, what I feel is the best practices in this situation is that you have a separate user|group combination for apache. However, apparently that is webapp currently, so I would not look into trying to change it. Check your apache httpd.conf file (should be somewhere in /etc or a directory underneath it) and see who the user/group is.
     
    To check out the entry for webapp, cat the /etc/passwd file and see what the entry for the webapp user is. I don't know why there wouldn't be a group there.
     
    In the apache httpd.conf file there is an entry for the user/group apache will run as. That should be webapp in this case.
     

    User webapp Group webapp
  10. gizmola's post in Php page image with text rewritten to function but... was marked as the answer   
    You should not be outputting an image header in a script that is simply creating an image and writing it to disk. Remove the
     

    Header ("Content-type: image/jpeg"); The other thing to look into is the path: 

    imagejpeg($image, 'vda-images/'.$n1.'.jpg', 80); Make sure that whatever process is running this php code has rights to rwx the vda-images directory.
  11. gizmola's post in Can a saved vagrant box handle a change in ISP ? was marked as the answer   
    What you want to do is change your network from public_network to "private_network". This will used the Nat adapter.
     
    Make sure the network is something that is unlikely to conflict with your home or work network. Something like '192.168.77.x'
  12. gizmola's post in what to do now ?! was marked as the answer   
    Learning to program can easily become a rabbit hole.
     
    Programming exists to create applications and systems that solve a problem or facilitate a business.
     
    The simple answer is, in order to progress as a programmer you need to actually program.
     
    Write down a design specification for something you want to build, and build it. Along the way you will need to problem solve. You will need to learn things you don't understand adequately at present, and you will fail, and in the process learn how to debug and become more competent.
     
    Let's say you read a bunch of books on carpentry, but never try to build anything? Would you hire that person to make you cabinets for your house?
     
    I know many developers who are starting out, who build things simply to have a portfolio showing what they can do.
     
    When I first started as a programmer, I made some silly applications that didn't do much, but in each case I learned a great deal. Eventually I created a freeware menu system (this was back in the days when DOS PC computers dominated the marketplace) and my software allowed you to create some simple text files that would be read in, and allow a user to navigate through the options and start programs. There were many such programs available at the time, but I built mine anyways, and used it on my computer and installed it on my parents computer.
     
    In creating it, I realized that I had a need to utilize record structures, linked lists, windowing libraries and file io. It required me to learn a lot of things and as a result I advanced as a programmer and this experience lead directly to a job that essentially started my professional programming career.
     
    With each project you learn more and become a more capable developer.
  13. gizmola's post in Please explain "FOR" loops was marked as the answer   
    For loops are just generic conditional control structures. The php syntax was borrowed from c, and it's common to many languages.
     
    In your example there's a problem because all php variables have to start with a '$'. But if we forget about that for a second, and just consider your question, here is what happened.
     
    What you wanted (echo a string 10x)
     

    $myVar = "This is awesome"; for ($i = 0; $i < 10; $i++){ echo $myVar . '<br>'; } What you did: 

    $myVar = "This is awesome"; for ($i = 0; $i < 10; $i++){ echo $myVar[$i] . '<br>'; } What is happening then? In this second case, what you are asking php to do, is to try and transform $myVar into an array from a string.PHP is happy to do this for you, as it already considers a string to be an array of characters.
     
    So what your code does is echo a single character from the $myVar string each time, and since $i is being incremented you get this:
     
    $myVar[0] .. then $myVar[1] .. then $myVar[2] etc. until the loop condition becomes false. In your example, it will loop 10 times, or up to 10 letters of the string: from $myVar[0] - $myVar[9].
     
    The loop itself is going to repeat the individual instructions contained within the control structure -- { ... } until the condition becomes false. With "for loops", you just have some place holders for built in variables that it will initialize, and increment or decrement each time the loop is entered.
     
    In other words, the $i is something that you may or may not want to be using inside the loop, but it's not required. Just to echo 10 strings, there is no need for you to reference $i inside the loop at all.
  14. gizmola's post in Creating a prepared statement from an array was marked as the answer   
    PDO::PARAM_STR is a constant defined with an integer value.
     
    There is absolutely no reason that you should have an issue assigning the value to an array element and using it later. It's an integer value when it's passed.
     
    We would have to see the code that does this "cramming" to understand whether your technique is valid or doing something different than what you think it is.
     
    With that said:
     

    $foo['type'] = PDO::PARAM_STR; Is entirely different from: 

    $foo['type'] == 'PDO::PARAM' . '_STR'; We need to know the specifics of what you were trying to do there that lead you down this path in the first place.
  15. gizmola's post in 4 bytes to float was marked as the answer   
    Here's a more modern, simpler and cleaner way of approaching this, that incorporates the advice already provided
     

    <?php $file = new SplFileObject("myfile.dat"); $raw = ''; while (!$file->eof()) { // Get one line from the file. $values = explode(',', $file->fgets()); $raw .= chr($values[1]); // Is this the 4th value? if (0 == $values % 4) { // Do whatever you need with the value. Just echoed it here echo unpack('f', $raw); $raw = ''; } } // Unset the file to close the file handle. $file = null;
  16. gizmola's post in Undefined Index if ID added to text field was marked as the answer   
    An undefined index occurs when you try and reference a key in an array that doesn't exist. Based on the info you provide that was the attempted referencing of "$_POST['company_address']". Clearly, prior to the api actually returning something, that variable didn't exist in the POST data.
     
    You can improve your error checking by using functions like array_key_exists or trying:
     

    if (isset($POST['some_key'])) { } else { // Deal with error, it's not going to work }
×
×
  • 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.