PhpSpreadsheet official recipe “Write a date or time into a cell” not working as excpected

I am following the recipe Write a date or time into a cell from official PHPSpreadsheet doc.

The only difference is that the 3 writes are on 3 different cells.

PhpOfficePhpSpreadsheetCellCell::setValueBinder( new PhpOfficePhpSpreadsheetCellAdvancedValueBinder() );

$spreadsheet = new Spreadsheet();
$spreadsheet->getActiveSheet()
    ->setCellValue('D1', '2008-12-31');

$spreadsheet->getActiveSheet()->getStyle('D1')
    ->getNumberFormat()
    ->setFormatCode(PhpOfficePhpSpreadsheetStyleNumberFormat::FORMAT_DATE_YYYYMMDDSLASH);

// PHP-time (Unix time)
$time = gmmktime(0,0,0,12,31,2008); // int(1230681600)
$spreadsheet->getActiveSheet()
    ->setCellValue('D2', PhpOfficePhpSpreadsheetSharedDate::PHPToExcel($time));
$spreadsheet->getActiveSheet()->getStyle('D2')
    ->getNumberFormat()
    ->setFormatCode(PhpOfficePhpSpreadsheetStyleNumberFormat::FORMAT_DATE_YYYYMMDDSLASH);

// Excel-date/time
$spreadsheet->getActiveSheet()->setCellValue('D3', 39813);
$spreadsheet->getActiveSheet()->getStyle('D3')
    ->getNumberFormat()
    ->setFormatCode(PhpOfficePhpSpreadsheetStyleNumberFormat::FORMAT_DATE_YYYYMMDDSLASH);

$writer = new PhpOfficePhpSpreadsheetWriterOds($spreadsheet);
$writer->save("/var/www/html/var/test.ods");

Opening the ods file with LibreOffice Calc, I have the 3 cells setted with content 39813 and no date formatting is applied.
enter image description here

Is the doc wrong or am I missing something?

PHP code not updating database: while loop not executing UPDATE statement

I have a PHP script that is supposed to update a row in my database based on the ID of the user. However, the whileloop I’m using to execute the UPDATEstatement is not working. Here’s the relevant code:

require_once 'Connect DB.php';
$i=0;
while ($i=0) {
  if (isset($_POST["modifi"])) {
    $id_user = $_POST["modifi"];
    if(isset($_POST["send"])){
      $sql = 'update users set
            nom_user=''.$_POST["nom"].'',prenom_user=''.$_POST["prenom"].'',age_user=''.$_POST["age"].'',tel_user=''.$_POST["tel"].'' where id_user = ''."$id_user".''';
      $stmt = $con->exec($sql);
      $i=1;
    }
  }
}

When I submit the form with the send button, the UPDATE statement does not execute and the loop continues indefinitely. I suspect the while condition is the problem, but I’m not sure how to fix it.

Can anyone help me understand why this code is not working and how I can fix it? Thank you.

String variable echos desired value but retains the ‘script’ that created it when I try to assign it to another string

Trying to pass a parameter ‘name’ to B.PHP based upon a link that was clicked on in A.PHP

This parameter will then be used to create the value for a ‘Where colum_name = value’ part of an SQL Query used in B.PHP

$sql = “Select stuff where Name = ” … append name parameter … “order by stuff”;

I use the following script in B.PHP to assign the ‘name’ passed to a parameter called ‘horse’. This works fine…

<script>
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[[]]/g, '\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';

 alert(decodeURIComponent(results[2].replace(/+/g, ' ')));  
    return decodeURIComponent(results[2].replace(/+/g, ' '));
}

 var horse = getParameterByName('horse')

 document.getElementById("horse").innerHTML = horse;

</script>

I then use the following code using an output buffer to build the sql query…

ob_start();

  echo  "SELECT rh.Race_Id, rh.RH_Position, r.Race_Date, r.Race_Course, r.Race_Title, 
        r.Race_Going, r.Race_Distance, r.Race_Value from racetable r
        join race_horse_table rh on r.Race_Id = rh.Race_Id
        join horsetable h on rh.Horse_Id = h.Horse_Id
        where h.Horse_Name = '" ;                    //Echo first part of query
  echo  "<script>document.write(horse)</script>";    //Get the name of the horse
  echo  "' order by Race_Date DESC;" ;               //Complete the query

  $sql  = ob_get_contents();  
  ob_get_clean();

When I echo this string it is exactly what I want it to be, but when I submit it to SQL
it receives the text “document.write(horse)” instead of the horse’s name

echo an SQL row for each using a checkbox and a submit button

I will simplify the code in order to highlight what I need:

<form id="highlighttable" name=form1 method="POST">
    
    <div class="form-group">
        <button name="save_multicheckbox" class="btn-primary">Save Checkbox</button>
    </div>
    <?php
      if(isset($_POST['save_multicheckbox'])){
        echo "<p>yes</p>";
        $checklist = $_POST['ckb'];
        foreach($checklist as $list) {
            echo "<p>as</p>";
        }
      }
    ?>
        <table>
        <tr id="col-title">
                    <th>Title</th>
                    <th>Type</th>
                    <th>Post Date</th>
                    <th>Url</th>
                    <th>Feature</th>
                </tr>

                <?php foreach($result as $res){
                        ?><tr>
                            <td><h6>Lorem</h6></td>
                            <td><h6>Lorem</h6></td>
                            <td><h6>Lorem</h6></td>
                            <td><h6>Lorem</h6></td>
                            <td id="h-center"><input type="checkbox" name="ckb[]" onclick="chkcontrol(<?php echo $res->chkbox_num; ?>)">
                                </td>
                            </tr>
                        <?php
                    } ?>
        </table>
 </form>

I have foreach from my select query, which outputs table rows below:

<?php foreach($result as $res){} ?>

output:

1

what I am trying to do is to echo or retrieve the rest of the columns on each selected row by marking what I want to get with a checkbox (last column)

<td id="h-center"><input type="checkbox" name="ckb" onclick="chkcontrol(<?php echo $res->chkbox_num; ?>)"></td>

my problem is that my foreach does not output the selected rows with that I tried below:

      if(isset($_POST['save_multicheckbox'])){
        echo "<p>yes</p>";
        $checklist = $_POST['ckb'];
        foreach($checklist as $list) {
            echo "<p>as</p>";
        }
      }

first I tried to add an echo inside the button to check if it works and it does, I am just wondering how to show the selected rows. Is there maybe an issue with the variable I am using to get it? my attempt is $checklist = $_POST['ckb']; where ckb is the name of the checkbox.

How can I remove the default alert and embed a quick view option for selecting product variants in the pop-up modal while using Flatsome&WooCommerce?

How can I modify the Flatsome theme and WooCommerce settings to achieve the following:

  • Remove the default alert that appears when a customer fails to choose a product variant.
  • Integrate a quick view option into the shopping process, allowing customers to easily select product variants from a pop-up modal if they initially forget to do so?

This would improve the user experience by providing a more seamless and convenient way for customers to choose product options without disrupting their shopping flow.

enter image description here

What I to add the functions.php, but did not work:


function flatsome_child_custom_js() {
    $custom_js = "
        jQuery(document).ready(function($) {
            $('body').on('click', '.single_add_to_cart_button', function(e) {
                let $variationForm = $(this).closest('.variations_form');
                
                if ($variationForm.length > 0 && !$variationForm.find('input[name="variation_id"]').val()) {
                    e.preventDefault();
                    e.stopPropagation();
                    
                    // Remove or comment the next line to disable the default message
                    
                }
            });
        });
    ";
    
    wp_add_inline_script('flatsome-js', $custom_js);
}

add_action('wp_enqueue_scripts', 'flatsome_child_custom_js', 20);

How to calculate Redis memory usage

I have an Elasticache Redis instance on AWS and I want to monitor its memory usage and send alerts when it exceeds a certain threshold. The Redis info command provides several memory-related metrics, including

used_memory:3651689760

used_memory_human:3.40G

used_memory_rss:3684122624

used_memory_rss_human:3.43G

used_memory_peak:3704319760

used_memory_peak_human:3.45G

used_memory_peak_perc:98.58%

maxmemory:20975001908

maxmemory_human:19.53G

I would like to calculate the total memory usage of Redis based on these metrics and send an alert when the usage exceeds a specific percentage.

Can anyone provide guidance on how to calculate Redis memory usage based on the info command output?

Thank you in advance for your help!

Can we replace the regular price of variable product by calculated price without plugin?

I want to change the regular price of the variable product by the calculated price but i’m able to change price only for simple product and my code is not working for variable product. Anyone please guide me to do it properly so its work for every type of product.Thanks

add_filter( 'woocommerce_add_cart_item_data', 'save_custom_data_in_cart_object', 30, 3 );
function save_custom_data_in_cart_object( $cart_item_data, $product_id, $variation_id ) {
    if( ! isset( $_POST['custom_text'] ) || empty( $_POST['custom_text'] ) && ! isset( $_POST['product_custom_price'] ) || empty( $_POST['product_custom_price'] ) )
        return $cart_item_data;


    // Get an instance of the WC_Product object
    $product = $variation_id > 0 ? wc_get_product($variation_id) : wc_get_product($product_id);

    $product_price = (float) $product->get_price(); // Get the product price
    // Get the text
    $custom_text = sanitize_text_field ( $_POST['custom_text'] );
    $product_custom_price = sanitize_text_field ( $_POST['product_custom_price'] );
    $cart_item_data['custom_data']['price'] = $product_custom_price * $custom_text ;
    $cart_item_data['custom_data']['text']  = $custom_text;
    // $cart_item_data['custom_data']['custom_price']  = $product_custom_price;
    if(!empty($custom_text) && !empty($product_custom_price)){
        echo "we filled with joyyyy:)";
        $multiplyPrice = $cart_item_data['custom_data']['price'];
        $regular_price = $multiplyPrice;
        $productID = $product_id;
        $product = wc_get_product($productID);
        // Set regular price
        $product->set_regular_price( $regular_price );
        // If your product has a Sale price
        
        $new_price = $regular_price;
            
        // Set new price
        $product->set_price( $new_price );

        // Save to database (Note: You might want to clear cache of your page and then reload, if it still doesn't show up go to the product page and check there.)
        $product->save();
    
    }


    return $cart_item_data;
}

i am trying to connect my html site to data base for which i am getting some errors [closed]

Warning: Undefined variable $conn in C:xampphtdocsMy Pic Databaseconnect.php on line 20

Fatal error: Uncaught TypeError: mysqli_stmt_init(): Argument #1 ($mysql) must be of type mysqli, null given in C:xampphtdocsMy Pic Databaseconnect.php:20 Stack trace: #0 C:xampphtdocsMy Pic Databaseconnect.php(20): mysqli_stmt_init(NULL) #1 {main} thrown in C:xampphtdocsMy Pic Databaseconnect.php on line 20

HTML CODE----->


 <form action="connect.php" method="post">
            <div class="lg:w-1/2 md:w-2/3 mx-auto">
            <div class="flex flex-wrap -m-2">
              <div class="p-2 w-1/2">
                <div class="relative">
                  <label for="name" class="leading-7 text-sm text-gray-600">Name</label>
                  <input type="text" id="name" name="name" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
                </div>
              </div>
              <div class="p-2 w-1/2">
                <div class="relative">
                  <label for="email" class="leading-7 text-sm text-gray-600">Email</label>
                  <input type="email" id="email" name="email" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
                </div>
              </div>
                <div class="p-2 w-1/2">
                  <div class="relative">
                    <label for="phone" class="leading-7 text-sm text-gray-600">Phone</label>
                    <input type="phone" id="phone" name="phone" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
                  </div>
                </div>
                <div class="p-2 w-1/2">
                  <div class="relative">
                    <label for="pack" class="leading-7 text-sm text-gray-600">Pack</label>
                    <select id="pack" name="pack" required class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out">
                      <option value="select">Select</option>
                      <option value="start">Start</option>
                      <option value="pro">PRO</option>
                      <option value="business">Business</option> 
                      <option value="special">Special</option>
                    </select>
                  </div>
                </div>  
                <div class="p-2 w-full">
                  <div class="relative">
                    <label for="message" class="leading-7 text-sm text-gray-600">Message</label>
                    <textarea id="message" name="message" class="w-full bg-gray-100 bg-opacity-50 rounded border border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 h-32 text-base outline-none text-gray-700 py-1 px-3 resize-none leading-6 transition-colors duration-200 ease-in-out"></textarea>
                  </div>
              </div>
              <div class="p-2 w-full">
                <button class="flex mx-auto text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded text-lg">Submit</button>
              </div>
            </form>


PHP CODE----->


<?php
$name = $_POST["name"];
$email = $_POST["email"];
$phone = filter_input(INPUT_POST,"phone",FILTER_VALIDATE_INT);
$pack = $_POST["pack"];
$message = $_POST["message"];

$host="localhost";
$dbname="myfirstpic";
$username="root";
$password="";

mysqli_connect($host, $username, $password, $dbname);
if(mysqli_connect_errno()){
die("Connection error: " . mysqli_connect_error());

}
$sql="INSERT INTO message (name, email, phone, pack, message)
        VALUES(?,?,?,?,?)";
$stmt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt,$sql)){
    die(mysqli_error($conn));
}
mysqli_stmt_bind_param($stmt,"ssiss",
                        $name,
                        $email,
                        $phone,
                        $pack,
                        $message);
mysqli_stmt_execute($stmt);
echo "Record Saved.";



?> 

i am trying to get contact us information of my project site into database

WordPress Post HTML Structure Alteration

My question is about the WordPress post structure. When we type content such as Headings and Paragraphs etc they are inserted simply as < h1> and < p> etc. See below the screenshot I captured from the code inspector:

enter image description here

What I want is to have a custom structure to better control my layout. Here is another screenshot where I want to wrap every head/paragraph/etc into a < div>:

enter image description here

So, whenever we enter any content via the WordPress editor it is wrapped into a div. Any idea if this is possible?

How does a PHP interface actually change the behavior of a class

According to PHP documentation,

Object Interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are implemented.

Hence, an interface is like a class with predefined method which still needs to be accessed with the -> symbol

However, the ArrayAccess Interface provides accessing of objects as arrays. Making it possible for an object to be accessed with both $object->property and $object["property"]

I cannot understand how the ArrayAccess makes it possible to change an object syntax. I’ve written out a code to try replicating the effect of just one of the ArrayAccess method but it throws an error

// Using the PHP ArrayAccess Interface

namespace A {
    
    class myclass implements ArrayAccess {
        public function offsetExists($offset) { return true; }
        public function offsetGet($offset) {
            // changed behaviour
            return $this->{$offset} ?? null;
        }
        public function offsetSet($offset, $value) {}
        public function offsetUnset($offset) {}
    }

    $myclass = new myclass();
    $myclass->access = 'Interface';
    echo $myclass['access']; // "Interface"

};

//Trying to implement my own ArrayAccess Interface

namespace B {
    
    interface MyArrayAccess {
        public function offsetGet($offset);
    }
    
    class myclass implements MyArrayAccess {
        public function offsetGet($offset) {
            // change behaviour
            return $this->{$offset} ?? null;
        }
    }
    
    $myclass = new myclass();
    $myclass->access = 'Interface';
    echo $myclass['access']; // Fatal error: Uncaught Error: Cannot use object of type Bmyclass as array

}

Please help me explain this properly. Thanks

WordPress menu item selective customization

I have a WordPress menu / wp_nav_menu setup like this:

<ul>
  <li><a href="">Link 1</a></li>
  <li><a href="">Link 2</a>
    <ul>
        <li><a href="">Sub-link A</a></li>
        <li><a href="">Sub-link B</a></li>
        <li><a href="">Sub-link C</a></li>
    </ul>
  </li>
  <li><a href="">Link 3</a></li>
</ul>

All I want is to change the structure of Link 2 from:

    <li><a href="">Link 2</a>
      <ul>
        <li><a href="">Sub-link A</a></li>
        <li><a href="">Sub-link B</a></li>
        <li><a href="">Sub-link C</a></li>
      </ul>
    </li>

To be like:

    <li><span>Link 2</span>
      <ul>
        <li><a href="">Sub-link A</a></li>
        <li><a href="">Sub-link B</a></li>
        <li><a href="">Sub-link C</a></li>
      </ul>
    </li>

Basically I want the second menu item not to be a link instead a span, rest of the structure remains the same. Is there a way we can target specific menu item?

PHP 7.4 depends on two versions of libssl

I need to compile PHP 7.4 on AlmaLinux 9 with PostgreSQL module support. openssl-devel (3.0) RPM is required by mysql-devel and PHP 7.4 doesn’t compile with OpenSSL 3. So I have compiled OpenSSL 1.1 from source and installed it in its default prefix path : /usr/local.
So PHP 7.4 compiles fine this way :

$ cd php-7.4.33
$ ./configure PKG_CONFIG_PATH='/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig' OPENSSL_LIBS="-L/usr/local/lib64/ -lssl -lcrypto" --with-apxs2 --with-pgsql --with-external-pcre --enable-mbstring --sysconfdir=/etc --with-config-file-path=/etc --enable-pdo --with-pdo-pgsql --with-zlib --with-zip --with-jpeg --with-pear --with-curl --enable-opcache --with-openssl --with-freetype --with-xpm --with-libdir=lib64 --with-ldap --with-mysqli --with-pdo-mysql --enable-soap --enable-gd --without-sqlite3 --without-pdo-sqlite --with-curl
$ make -j $(nproc)

I got this warning :

/usr/bin/ld: ext/openssl/.libs/openssl.o: in function `php_openssl_load_cipher_mode':
php-7.4.33/ext/openssl/openssl.c:6499: undefined reference to `EVP_CIPHER_flags'

The problem is that libpq.so depends on libssl.so.3 and PHP on libssl.so.1.1, so ld.so must load two versions of the same SO :

$ ldd sapi/cli/php | egrep "ssl|crypto|pq"
        libpq.so.5 => /lib64/libpq.so.5
        libssl.so.1.1 => /usr/local/lib64/libssl.so.1.1
        libcrypto.so.1.1 => /usr/local/lib64/libcrypto.so.1.1
        libssl.so.3 => /lib64/libssl.so.3
        libcrypto.so.3 => /lib64/libcrypto.so.3
$ ldd /usr/lib64/libpq.so
        libssl.so.3 => /lib64/libssl.so.3
        libcrypto.so.3 => /lib64/libcrypto.so.3

My question is, what ls.so will do if objects of the same name exist in these two SO files (libssl.so.1.1 and libssl.so.3) ? php-cli seems to work but I’ve not tested PostgreSQL connexion yet.

Many thanks

How to locate framework api with high cpu usage for php-fpm

I’m optimising for some slow, high-occupancy api using the laravel and thinkphp framework
The slow-logging api in php-fpm have all been migrated to separate containers, but there are still some local php-fpm processes that are suddenly taking up a lot of cpu.
However, there are still some php-fpm processes on the local machine that are suddenly taking up a lot of cpu, is there any tool or solution that can locate which interface these processes are requesting?

I confirm that opcache is enabled

So I’m looking for a tool or a solution that can meet the requirements

I’ve looked at xhgui, but it seems to only return memory usage and cpu usage time.

Cant’ access laravel public folder on IOS device only

Uploaded video in laravel cannot access in IOS Device. It shows blank and alert this content is not available. Other OS working fine except skip issue.
I use Shared Hosting Cpanel and Laravel 8.
I did php artisan storage:link. IOS device cannot access any file inside laravel public folder.
What is this problem.

I tried htaccess and other configuration related this error. I cannot find and what should i do

Drupal 9 CK editor 5 does not render the code

The CK editor 5 in Drupal 9.5 doesn’t render the HTML and JS Code. It just displays the raw code.

Custom block code:

Custom block code

Rendered output:

rendered output

I tried two ways; one is default way provided by ck editor to add code which is shown in the image. The other way is a traditional way to add code. By choosing the source I put html and JS codes.In this way the special characters in JS code like “<“, “>” are converted into escapes. So neither way is working.