Skip to content

Tag: php

PHP Date Function Seven days previous

I am trying to use PHP’s Date Function to get the date of 7 days earlier in YYYY-MM-DD format. when i try i get an error Answer Use the strtotime method provided by PHP. date(‘Y-m-d’, strtotime(‘-7 days’)) Thanks to @lonesomeday for pointing out my mistake in the comments 😉

Multiple Uniques MYSQL

I have some code im trying to get working. What im looking for is to have it so that i query a site, then display results and upload to database. I want it to ignore duplicates which i have working by checking the date. issue im having is when a user searches for another stock ticker it does not insert

Check if a PHP cookie exists and if not set its value

I am working on a multilingual site so I tried this approach: The idea is that if the client doesn’t have an lg cookie (it is, therefore, the first time they’ve visited this site) then set a cookie lg = ro for that user. Everything works fine except that if I enter this page for the first time, th…

PHP SESSION variable get’s deleted each reload

Does anybody know what can cause the $_SESSION variable to be cleared? The session variable is used to keep track of products in the cart. Everything worked perfect on the development and production server. Out of a sudden the production server looses the session variable – without any changes updated. …

PHP Session variable not getting set

In one page of our site, I have this code: and further down, this button control: Now, in the register template, I have this code: But it only shows the value as /. What could be going on that is causing this? Answer What I ended up doing was sending a post variable to the page. The difference in the

explode an array of delimited strings into two arrays

I have the following array: that I need to split into two arrays using “-” as delimiter: and Is there anything like array_explode that does what I want? or a combination of php array functions? I’d like to do this without going through my own for/each loop, if possible, or at least minimize …

PHPStorm: correct PHPDoc for a Collection of Objects?

I’m using the PHPStorm IDE, and run into trouble when I run the code inspection. I have a method which returns a collection of objects. The Collection itself is an object, which has its own methods, and implements the Traversable interface: If I document findByUser() to return a Collection, the code ins…

PDO get the last ID inserted

I have a query, and I want to get the last ID inserted. The field ID is the primary key and auto incrementing. I know that I have to use this statement: That statement works with a query like this: But if I want to get the ID using this statement: I get this error: What am I doing wrong?