Handle exceptions in Laravel Event Listener

I want to handle Exceptions in my Listener exactly in handle() method

/**
 * Handle the event.
 *
 * @param DocumentGenerated $event
 * @return void
 */
public function handle(DocumentGenerated $event)
{
    $data = $event->data;
    $this->generateDoc($data);
}

After I read the documentation I found that the handle() method of the listener should return false to stop the event propagation.

I changed the return type of the handle() method from void to boolean and tried returning false but it didn’t stop the event propagation.

image appears corrupted when downloaded from excel file

It takes the picture column from the Excel file and downloads the pictures in each row and the downloaded pictures do not open in the file.

   
            // Resim indirme işlemleri
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $imageUrl);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

            $imageData = curl_exec($ch);
            curl_close($ch);

            // Resimleri img dosyasına kaydetme işlemleri
            $imageFile = "img/" . basename($imageUrl);
            $file = fopen($imageFile, "wb");
            fwrite($file, $imageData);
            fclose($file);

            // İndirilen resmi direk olarak siteye ekle
            $img = "<img src='img/" . basename($imageUrl) . "' alt='Resim'> <br>";
            echo $img;

        }
    }
}


$img = "img/";
$files = scandir($img);

foreach($files as $file) {
    if($file !== '.' && $file !== '..') {
        echo '<img src="' . $img . $file . '" alt="Resim"><br>';
    }
}

WordPress Blog Template content-blog.php current post_id

I want to style the first element of the blog different and i need a possibility to find it in php. I used the coming expression, but it shows only the first element: $postID=$wp_query->current_post;
The post of this Variable is always 0.
Here my Code, i hope someone have a solution for me. I use the Astra Theme with a Child Theme… and its the content-blog.php

    <?php
/**
 * Template part for displaying posts.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Astra
 * @since 1.0.0
 */

?>
<?php astra_entry_before(); ?>
<?php
$postID=$wp_query->current_post;
$marginPosition = '';
if ($postID != 0 && !is_paged()) :
    if($postID % 2 == 0 || $postID % 3 == 0) {
        $marginPosition = 'left-margin';
    }
    if($postID % 3 == 0){
        $marginRightPosition = "no-right-margin";
    }
    if($postID % 4 == 0){
        $marginPosition = '';
    }
    if($postID % 5 == 0){
        $marginPosition = 'left-margin';
    }
endif;
    echo $postID;
?>
<article
<?php
        echo astra_attr(
            'article-blog',
            array(
                'id'    => 'post-' . get_the_id(),
                'class' => join( ' ', get_post_class() ).' '.$marginPosition. ' '.$marginRightPosition,
            )
        );
        ?>
>
    <div class="article-holder <?php if( $postID == 0 && !is_paged() ) : ?>firstarticle<?php else: ?>standard-article<?php endif; ?>">

        <?php if( $postID == 0 && !is_paged() ) : ?>
            <div class="left">
                <div class="featured-image">
                    <a href="<?php the_permalink();?>">
                    <?php the_post_thumbnail( 'featured-blog-size' ); ?>
                    </a>
                </div>
            </div>
            <div class="right">
                <div class="title"><h2><a href="<?php the_permalink();?>"><?php echo get_the_title( ); ?></a></h2></div>
                <div class="latest-banner"><span>latest article</span></div>
                <?php echo do_shortcode( '[molongui_author_box]' ); ?>

            </div>
        <?php else: ?>
        <div class="top">
            <div class="standard-image">
                <a href="<?php the_permalink();?>">
                    <?php the_post_thumbnail( 'standard-blog-size' ); ?>
                </a>
            </div>
        </div>
        <div class="bottom">
            <div class="title"><h2><a href="<?php the_permalink();?>"><?php echo get_the_title( ); ?></a></h2></div>
            <div class="written-by-content">
                <div class="right-wb">
                    <span>by <a href="#">Josephine Choo</a>, PhD<br></span>
                    <span>Consultant</span>
                    <div class="date"><?php echo get_the_date( 'F dS Y' ); ?></div>
                </div>
            </div>
        </div>
        <?php endif; ?>
    </div>
</article><!-- #post-## -->
<?php astra_entry_after(); ?>


Woocommerce progress bar to show product limits in cart

I’m developing a very special ecommerce that allows the insertion of up to 21 products in the cart.
How do I show a progress bar in the cart to show users how close they are to the limit.
Thank you

I managed to put a limit on it by inserting the following code, but you’ll want to make it a little more graphical with a progress bar

add_filter( 'woocommerce_update_cart_validation', 'only_six_items_allowed_cart_update', 10, 4 );
function only_six_items_allowed_cart_update( $passed, $cart_item_key, $values, $updated_quantity ) {

    $cart_items_count = WC()->cart->get_cart_contents_count();
    $original_quantity = $values['quantity'];
    $total_count = $cart_items_count - $original_quantity + $updated_quantity;

    if( $cart_items_count > 21 || $total_count > 21 ){
        // Set to false
        $passed = false;
        // Display a message
         wc_add_notice( __( "You cannot have more than 21 books in your cart", "woocommerce" ), "error" );
    }
    return $passed;
}

PHP E-Mail form not submitting/getting called

so I am trying to make a simple contact form with html and php.
My code seems to be more or less fitting, but when pressing the submit button, all that happens, is the site getting reloaded…
Please be aware, that some variable names/texts are in german, but that should not effect the code.

I am basically trying to call the contact.php file, by pressing the submit button, unfortunately, all that happens is the site reloading and not sending the mail.
Here is the html code:

<form action="contact.php" method="post" class="cnt-form">
          <div class="form-input">
              <label for="name">Name*</label>
              <input type="text" name="name" placeholder="Max Mustermann" required="">
          </div>
          <div class="form-input">
              <label for="name">Firma</label>
              <input type="text" name="firma" placeholder="Mustermann GmbH"
          </div>
          <div class="form-input">
              <label for="name">Straße</label>
              <input type="text" name="strasse" placeholder="Musterstraße 1">
          </div>
          <div class="form-input">
              <label for="name">PLZ</label>
              <input type="text" name="plz" placeholder="1234" pattern = "[0-9]{4}">
          </div>
          <div class="form-input">
              <label for="name">Ort</label>
              <input type="text" name="ort" placeholder="Musterstadt">
          </div>
          <div class="form-input">
              <label for="email">Email*</label>
              <input type="text" name="email" placeholder="[email protected]" required="" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$">
          </div>
          <div class="form-input">
              <label for="telefon">Telefon*</label>
              <input type="tel" name="telefon" placeholder="1234 1234567890" required="">
          </div>
          <div class="form-input">
              <label for="subject">Betreff*</label>
              <input type="text" name="subject" placeholder="Betreff" required="">
          </div>
          <div class="form-input">
              <label for="message">Nachricht*</label>
              <textarea name="message" placeholder="Geben Sie hier Ihren Informationswunsch ein." required=""></textarea>
          </div>
          <input type="submit" name="send" class="btn" value="Senden">
      </form>

Here the php code in the contact.php file:

<?php

if(isset($_POST['send']) ) {
    $recipient = "[email protected]";

    $name = "";
    $firma = "";
    $strasse = "";
    $plz = "";
    $ort = "";
    $telefon = "";
    $email = "";
    $subject = "";
    $message = "";
    $email_body = "<div>";



    if(isset($_POST['name'])) {

        $name = filter_var($_POST['name'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>Absender:</b></label>&nbsp;<span>".$name."</span>

</div>";

    }
    if(isset($_POST['firma'])) {

        $firma = filter_var($_POST['firma'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>Firma:</b></label>&nbsp;<span>".$firma."</span>

</div>";

    }
    if(isset($_POST['strasse'])) {

        $strasse = filter_var($_POST['strasse'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>Straße:</b></label>&nbsp;<span>".$strasse."</span>

</div>";

    }

    if(isset($_POST['plz'])) {

        $plz = filter_var($_POST['plz'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>PLZ:</b></label>&nbsp;<span>".$plz."</span>

</div>";

    }

    if(isset($_POST['ort'])) {

        $ort = filter_var($_POST['ort'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>Ort:</b></label>&nbsp;<span>".$ort."</span>

</div>";

    }

    if(isset($_POST['telefon'])) {

        $telefon = filter_var($_POST['telefon'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>Telefon:</b></label>&nbsp;<span>".$telefon."</span>

</div>";

    }




    if(isset($_POST['email'])) {

        $email = str_replace(array("r", "n", "%0a", "%0d"), '', $_POST['email']);

        $email = filter_var($email, FILTER_VALIDATE_EMAIL);

        $email_body .= "<div>

<label><b>E-Mail:</b></label>&nbsp;<span>".$email."</span>

</div>";

    }



    if(isset($_POST['subject'])) {

        $subject = filter_var($_POST['subject'], FILEINFO_RAW);

        $email_body .= "<div>

<label><b>Betreff:</b></label>&nbsp;<span>".$subject."</span>

</div>";

    }



    if(isset($_POST['message'])) {

        $message = htmlspecialchars($_POST['message']);

        $email_body .= "<div>

<label><b>Anfrage:</b></label>

<div>".$message."</div>

</div>";

    }

    $email_body .= "</div>";


    $headers  = 'Anfrage von '. $name;



    if(mail($recipient, $subject, $email_body, $headers)) {

        function_alert("Wir bedanken us für Ihre Anfrage! Sie werden in Kürze eine Rückmeldung erhalten.");

    } else {

        function_alert("Anfrage konnte nicht versendet werden. Bitte versuchen Sie es später erneut!");

    }


} else {

    function_alert("Ups... Etwas ist schiefgelaufen. Bitte versuchen Sie es später erneut!");

}
function function_alert($msg): void
{
    echo "<script type='text/javascript'>alert('$msg');</script>";
}

Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP[PDO]

I try to Insert Multiple Records in my DB but give error when I use the third INSERT Statement
I need Help Plz.

I’ve looked through all the other StackOverflow (and google) posts with the same problem, but none seemed to address my problem.

I am using PDO and PHP.

My code:

 <?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";

try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  // begin the transaction
  $conn->beginTransaction();
  // our SQL statements
  $conn->exec("INSERT INTO emp (emp_name, emp_address, emp_salary, join_date)
  VALUES ('John', 'Doe', '5000', '30.03.2022')");
  $conn->exec("INSERT INTO emp (emp_name, emp_address, emp_salary, join_date)
  VALUES ('Johny', 'Doeo', '50000', '30.05.2022')");
  $conn->exec("INSERT INTO emp (femp_name, emp_address, emp_salary, join_date)
  VALUES (Johnn', 'Doeoo', '500000', '30.06.2022)");

  // commit the transaction
  $conn->commit();
  echo "New records created successfully";
} catch(PDOException $e) {
  // roll back the transaction if something failed
  $conn->rollback();
  echo "Error: " . $e->getMessage();
}

$conn = null;
?> 

Doctrine FindBy DateTime Infinite Process

i have a problem when i want query a row in my mysql database.
The ‘p_release_date’ field is type with datetime with doctrine. And after an insert, the format is 2023-03-24 00:00:00.

When i click on my Vue.js component, it return a date like this :

Fri Mar 24 2023 06:05:00 GMT+0100 (heure normale d’Europe centrale)

I transform my date in PHP DateTime :

$datetime = DateTime::createFromFormat('D M d Y H:i:s e+', $datas['date']);
$datetime->settime(0, 0);

Then when i made my query, the response return nothin, and i have infinite process on my network devtool :

$projects = $this->em->getRepository(Project::class)->findBy(['release_date' => $datetime]);

If someone has an issue, it will be useful.
Thanks a lot and have a nice day.

I try to made a query with doctine on my mysql table, filter by DateTime.
Currently it return nothin and a infinite process.
I expected it returns rows.

Pimcore Install fails due to non-resovlvable set of packages

I fail to install Pimcore. When following https://pimcore.com/docs/pimcore/current/Development_Documentation/Getting_Started/Installation.html I get the following error:

Your requirements could not be resolved to an installable set of packages.

Problem 1
– pimcore/pimcore[v10.5.0, …, 10.6.x-dev] require ext-gd * -> it is missing from your system. Install or enable PHP’s gd extension.
– Root composer.json requires pimcore/pimcore ^10.5 -> satisfiable by pimcore/pimcore[v10.5.0, …, 10.6.x-dev].

  • I DO HAVE gd installed and enabled
  • I’m running on WSL2
  • I’m on php 8.16
  • Apache 2.4

Bye

Michael

Correlated sub selects with COUNT condition from another table

I am having problem with figuring out a mysql querry. The pseudo code would be like this:
table 1 is users table
table 2 is a posts table, and I need to select only those users, who had minimum 5 posts within the time of 1000-2000 seconds of activity.

SELECT * FROM table1 WHERE **( COUNT(id) FROM table2 WHERE `user`=user_id.table1 AND `time`> 1000 AND `time`< 2000 ) > 5** AND active.table1 = 1 LIMIT 0,10

Thank you for help in advance.

Laravel – How to run a controller or call URL every X minutes WITHOUT composer

In advance, excuse me for my bad English.

I am looking for alternatives to be able to call a controller or a specific URL from the server, but this server is isolated from any internet connection and will not have a composer. Therefore I can’t run “php artisan” commands
At the moment it should work on Windows.

  1. I have laravel 10.x
  2. I have everything created to run a scheduler (but due to the limitation of not having a composer I can’t run it)
  3. I have mysql and sqlserver (for both it should work if the solution comes from here)

It would be impossible?

Call a url or controller from laravel every X time, from PHP or Windows or Mysql/SQL-server

How do fix Arabic word turns into symbols?

I am using Yii2 with php 8.0 and I try to insert values into the database using an excel sheet. when I tried to upload an Arabic word (متلازمة داون) it turn into ‘متلازمة داون’ while inserting into Postgres. when using it in the select query it shows the same Arabic word.

Script aborts after 300 seconds, although max_execution_time = 2400 is defined in php.ini

I have a local xampp with php8 installed.

  • Testing 1
    echo ini_get('max_execution_time');
    also results the 2400 from php.ini

  • Testing 2

    echo "Max execution time: ".ini_get("max_execution_time")."<br />";

    echo "Max input time: ".ini_get("max_input_time")."<br />";

Max execution time: 2400

Max input time: 60

  • ini_set(‘MAX_EXECUTION_TIME’, ‘-1’);
    no change

  • Error
    Fatal error: Maximum execution time of 300 seconds exceeded in C:xampphtdocs..incdatenbank.php on line xx

Php code to insert data into a table is working only once [duplicate]

<?php
    $con=mysqli_connect("host","user","pwd","db") or die("Connection failed:" .mysqli_connect_error());
    if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["submit"])) {
        $name = $_POST["name"];
        $hidename = $_POST["hidename"];
        $title = $_POST["title"];
        $confession = $_POST["confession"];
        $comments = $_POST["comments"];
        $email1 = $_POST["email1"];
        $email2 = $_POST["email2"];
        $email3 = $_POST["email3"];
        $email4 = $_POST["email4"];
        $email5 = $_POST["email5"];
        $sql = "INSERT INTO confessions (username,title,confession,hidename,comments,email1,email2,email3,email4,email5) VALUES ('$name', '$title', '$confession', '$hidename', '$comments', '$email1' ,'$email2', '$email3', '$email4', '$email5')";
        mysqli_query($con, $sql);
        echo("Confession saved");
    }
    ?>

I want to insert these inputs into a database in phpadmin. This code worked once, and then it stopped working for a few hours. I edited the code made many changes, and again, it worked once and it stopped working. I edited the code all over again, and for the third time, it worked for once, and it stopped working, I am using Dreamhost servers which use PHP 8.1 FastCGI to build this website. It worked once and stopped working for a few hours three times, and all three times, it was different code. I don’t know what I am doing wrong.

I tried changing the code three times using YouTube tutorials. I’ve also tried closing the connection, but it did not work.