How to display the text with the value at the same time from my dropdownlist select option tag?

I am trying to display these centimeters in my dropdownlist along with the price which was put on my value

<label>Select Height</label>
                  
                  <select name="psheight" id="psheight" style="width:50%;" class="form-control form-control-sm rounded-0" onchange="changeddl(this)"  >
                  <?php
                    $conn = $pdo->open();

                    try{
                      $now = date('Y-m-d');
                      $stmt = $conn->prepare("SELECT * FROM customize_ps_height");
                      $stmt->execute();
                      foreach($stmt as $row){
                          
                      ?>
                      
                        <option value="<?php echo $row['price'];?> <?php echo $row['height'];?>"><?php echo $row['height']; ?></option>
                        
                      <?php
                        
                     
                      }
                    }
                    catch(PDOException $e){
                      echo $e->getMessage();
                    }

                    $pdo->close();
                  ?>
                </select>
                  <div class="divheight" class="height-style"></div>
                <div class="divprice" class="price-style"></div>
<script>
  function changeddl($this){
    
$($this).next('.divheight').text($this.value>0?("Height: " + $this.value + " ₱"):"");
   $($this).next('.divprice').text($this.value>0?("Price: " + $this.value + " ₱"):"");

   
};
</script>

heres my output but i wanted also to display the centimeter which is selected

PHP contact form is not sending to e-mail and keep on showing the error alert [duplicate]

Hope you are having a good day. I have a problem of PHP and JS contact form. They failed to send the form to my e-mail address. I have read all the articles related to my problems but it didn’t seem to solve the issue. Please help 🙁

PHP Code

`

<?php


// specify your email here

$to = '[email protected]';



    // Assigning data from $_POST array to variables
    if (isset($_POST['name'])) { $name = $_POST['name']; }
    if (isset($_POST['email'])) { $from = $_POST['email']; }
    if (isset($_POST['number'])) { $number = $_POST['number']; }
    if (isset($_POST['title'])) { $title = $_POST['title']; }
    if (isset($_POST['message'])) { $message = $_POST['message']; }
    
    // Construct subject of the email
    $subject = 'Inquiries from ' . $number;

    // Construct email body
    $body_message .= 'Name: ' . $name . "rn";
    $body_message .= 'Email: ' . $from . "rn";
    $body_message .= 'Phone: ' . $number . "rn";
    $body_message .= 'Subject: ' . $title . "rn";
    $body_message .= 'Message: ' . $message . "rn";

    // Construct headers of the message
    $headers = 'From: ' . $from . "rn";
    $headers .= 'Reply-To: ' . $from . "rn";

    $mail_sent = mail($to, $subject, $body_message, $headers);

    if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
        window.alert("Thank you! We'll be in touch soon!");
        </script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
                    window.alert("Error! Please Try Again Later.");
                </script>
<?php
    } // End else
    
?>

`

Javascript

`

function checkmail(input){
  var pattern1=/^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/;
    if(pattern1.test(input)){ return true; }else{ return false; }}     
    function proceed(){
        var name = document.getElementById("name");
            var email = document.getElementById("email");
            var number = document.getElementById("number");
            var title = document.getElementById("title");
            var msg = document.getElementById("message");
            var errors = "";
            if(name.value == ""){ 
            name.className = 'error';
            return false;}    
              else if(email.value == ""){
              email.className = 'error';
              return false;}
                else if(checkmail(email.value)==false){
                    alert('Please provide a valid email address.');
                    return false;}
                else if(number.value == ""){
                    number.className = 'error';
                    return false;}
              else if(title.value == ""){
                    title.className = 'error';
                    return false;}
              else if(msg.value == ""){
                    msg.className = 'error';
                    return false;}
              else 
            {
      $.ajax({
          type: "POST",
          url: "php/submit.php",
          data: $("#contact_form").serialize(),
          success: function(msg){
          //alert(msg);
          if(msg){
              $('#contact_form').fadeOut(1000);
              $('#contact_message').fadeIn(1000);
                  document.getElementById("contact_message");
              return true;
          }}
      });
}};

`

HTML

`

<!--======= Contact Section =========-->
    <section class="sectoion-100px contact">
      <div class="container"> 

        <!-- Tittle -->
        <div class="tittle">
          <h4>CONTACT US</h4>
          <p>Feel free to ask anything</p>
        </div>
        <div class="contact-form"> 
          <!--======= FORM  =========-->
          <form role="form" id="contact_form" class="contact-form" method="post" onSubmit="return proceed()" action="php/submit.php">
            <div class="row">
              <div class="col-md-12">
                <ul class="row">
                  <li class="col-sm-6">
                    <label>
                      <span class="required">
                      <input type="text" class="form-control" name="name" id="name" placeholder="*Name" minlength="2" required="required">
                      </span>
                    </label>
                  </li>
                  <li class="col-sm-6">
                    <label>
                      <span class="required">
                      <input type="email" class="form-control" name="email" id="email" placeholder="*E-mail" pattern="^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$" oninvalid="setCustomValidity('Invalid e-mail')" oninput="setCustomValidity('')" required="required">
                      </span>
                    </label>
                  </li>
                  <li class="col-sm-6">
                    <label>
                      <span class="required">
                      <input type="tel" class="form-control" name="number" id="number" placeholder="*Mobile" pattern="^[0]d{9,11}$" oninvalid="setCustomValidity('Invalid phone number')" oninput="setCustomValidity('')" minlength="10" required="required">
                      </span>
                    </label>
                  </li>
                  <li class="col-sm-6">
                    <label>
                      <input type="text" class="form-control" name="title" id="title" placeholder="Subject">
                    </label>
                  </li>
                </ul>
              </div>
              <div class="col-md-12">
                <ul class="row">
                  <li class="col-sm-12">
                    <label>
                      <span class="required">
                      <textarea class="form-control" name="message" id="message" rows="1" placeholder="*Message" minlength="10" required="required"></textarea>
                      </span>
                    </label>
                  </li>
                  <li class="col-sm-12 no-margin">
                    <button type="submit" value="submit" class="btn" id="btn_submit">Send</button>
                  </li>
                </ul>
              </div>
            </div>
          </form>
        </div>
        
      </div>
    </section>

`

I have read the articles, tried to follow as advised, but.. it didn’t work for me 🙁

I tried everything but it keeps on showing error.
Also, how to show the success window alert if it’s succeeded?
It only shows the error alert.

PHP – How to display messages from an array (API) with a timeout between them but push new incoming messages at the end of the queue [duplicate]

Let’s say I have an API response as an array.

$data = [
  ['id' => 1, 'message' => 'Message 1', 'displayed' => false ],
  ['id' => 2, 'message' => 'Message 2', 'displayed' => false ],
]

I want to display the messages to the frontend with a sleep between them.

But this data is real-time data so that new messages can be inserted from external systems. I want those new messages to be inserted at the end of the queue (before undisplayed messages).

How can I create a function that displays the $currentMessage?

Issue when converting mysql_fetch array to $wpdb->get results within WP Shortcode

I am looking to deliver a dropdown within the page of a WordPress Theme connecting to the backend WP Database using $wpdb and ob_start to bring through option values.

In order to do this I have had to convert mysql_fetch array to $wpdb->get results and use a Shortcode generated from a PHP Snippet plugin.

Code –

add_shortcode( 'get-city', function () {
    ob_start(); ?>
   <?php
    global $wpdb;
    $results = $wpdb->query("SELECT countryid FROM {$wpdb->prefix}city");?>
    <select name="city"> 
    <option>Select City</option> 
    <?php while($row=$wpdb->get_results($results)) {
           echo "<option value>{$row->city}</option>";
    }
    echo "</select>";
    
    return ob_get_clean();
});

The shortcode shows no errors and is able to be activated.

The dropdown shows on the page but then no options are presented for a user to select. Nothing is being brought through from the db.

I would really appreciate it if someone could point out the error.

Thanks in advance.

Convert stdClass object into a PHP array

I get this JSON back

stdClass Object ( [status] => stdClass Object ( [timestamp] => 2022-11-17T10:41:36.783Z [error_code] => 0 [error_message] => [elapsed] => 1 [credit_count] => 1 [notice] => ) [data] => stdClass Object ( [1] => stdClass Object ( [symbol] => w80iz51y4ka [id] => 1 [name] => omu2f57cwof [amount] => 1 [last_updated] => 2022-11-17T10:41:36.783Z [quote] => stdClass Object ( [GBP] => stdClass Object ( [price] => 0.436996948831 [last_updated] => 2022-11-17T10:41:36.783Z ) [LTC] => stdClass Object ( [price] => 0.201879205801 [last_updated] => 2022-11-17T10:41:36.783Z ) [USD] => stdClass Object ( [price] => 8977 [last_updated] => 2022-11-17T10:41:36.783Z ) ) ) ) )

I dont know how to handle this “stdClass Object”. There are a lot in.

At postmen I get this result

{
    "status": {
        "timestamp": "2022-11-17T08:53:52.920Z",
        "error_code": 0,
        "error_message": null,
        "elapsed": 1,
        "credit_count": 1,
        "notice": null
    },
    "data": {
        "2": {
            "symbol": "ymtwz9qdk3",
            "id": 2,
            "name": "9t5ci78gq36",
            "amount": 1,
            "last_updated": "2022-11-17T08:53:52.920Z",
            "quote": {
                "GBP": {
                    "price": 0.9733139411311549,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                },
                "LTC": {
                    "price": 0.564631913659549,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                },
                "USD": {
                    "price": 8956,
                    "last_updated": "2022-11-17T08:53:52.920Z"
                }
            }
        }
    }
}

I How can I convert this to an array in PHP?
I test a lot also some solutions from other posts. But I am lost a bit.

Thanks and kind regards
Markus

list customers who bought a specific product with name, email and quantity in woocommerce

I am looking for a simple script, to be used by the administrator, that can displays how many of a specific product has been bought in woommerce:

  1. product: 43764
  2. John doe, [email protected], bouhgt this item: 4 times
  3. dave dimp, [email protected], bouhgt this item: 2 times
  4. jane chimp, [email protected], bouhgt this item: 6 times

I have tried a alot of scipts but mainly they seem to be based to be used for customer or a specific user_id.

PHPStan reports undefined variable in PHPStan, but it’s defined in included script

I have an application where I define some variables in a file (a.php), then include this from another file (b.php). PHPStan is complaining about undefined variables.

Simplified example:

a.php:

$config['foo'] = 'bar';

b.php:

<?php

require 'a.php';

//new SlimApp($config)->run();
echo $config;

PHPStan says:

------ ---------------------------------------- 
  Line   b.php                                   
 ------ ---------------------------------------- 
  :6     Variable $config might not be defined.  
 ------ ---------------------------------------- 

Also: I don’t know why but if I remove the <?php line at the beginning of b.php, the warning goes away.

How can I have PHPStan realize that $config is actually defined?

Btw I am aware of this question. It is not the same problem as I am explicitly including the file where the variable is defined.

PHP deleting file from another harddrive

I’m trying to delete a file which is on another hard drive (F:)

$filePath = $_POST['path']; //F:/documents/918/20221117.pdf
unlink($filePath);

It just throws

Warning: unlink() [function.unlink]: No error in C:wwwdeleteFile.php on line 351

PHP Version is 5.1 (yup…)

What is correct Laravel Horizon Environment Configuration To Send Bulk Email(60,000+)

What is the best Laravel Horizon Environment configuration to send bulk email(60,000+) on a 4GB RAM server , i tried the below but it keeps crashing my redis server when sending the emails.

'supervisor-email' => [
            'connection' => 'redis',
            'queue' => ['bulkEmail', 'fastCron'],
            'balance' => 'auto',
            'processes' => 500,
            'tries' => 3,
            'minProcesses' => 1,
            'maxProcesses' => 500,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,

with the above, 60,000+ email was queued to finish sending within 3-4hrs but My redis server keep crashing, What is the best configuration to use to avoid crashing and also make the queued job execute on time.
Thanks

How insert multiple file in database in same row

if(isset($_POST['submit'])){ 
    // File upload configuration 
    mkdir("public/$order_id", 0770, true);
    $targetDir = "public/$order_id/"; 
    $allowTypes = array('jpg','png','jpeg','gif'); 
     
    $statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = ''; 
    $fileNames = array_filter($_FILES['files']['name']); 
    if(!empty($fileNames)){ 
        foreach($_FILES['files']['name'] as $key=>$val){ 
            // File upload path 
            $fileName = basename($_FILES['files']['name'][$key]); 
            $targetFilePath = $targetDir . $fileName; 
             
            // Check whether file type is valid 
            $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
            if(in_array($fileType, $allowTypes)){ 
                // Upload file to server 
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){ 
                    // Image db insert sql 
                    $insertValuesSQL .= "('".$order_id."','".$fileName."', NOW()),"; 
                }else{ 
                    $errorUpload .= $_FILES['files']['name'][$key].' | '; 
                } 
            }else{ 
                $errorUploadType .= $_FILES['files']['name'][$key].' | '; 
            } 
        } 
         
        // Error message 
        $errorUpload = !empty($errorUpload)?'Upload Error: '.trim($errorUpload, ' | '):''; 
        $errorUploadType = !empty($errorUploadType)?'File Type Error: '.trim($errorUploadType, ' | '):''; 
        $errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType; 
         
        if(!empty($insertValuesSQL)){ 
            $insertValuesSQL = trim($insertValuesSQL, ','); 
            // Insert image file name into database 
            $insert = $db->query("INSERT INTO idcardprint (orderid,img1, date) VALUES $insertValuesSQL"); 
            if($insert){ 
                $statusMsg = "Files are uploaded successfully.".$errorMsg; 
            }else{ 
                $statusMsg = "Sorry, there was an error uploading your file."; 
            } 
        }else{ 
            $statusMsg = "Upload failed! ".$errorMsg; 
        } 
    }else{ 
        $statusMsg = 'Please select a file to upload.'; 
    } 
} 
?>

I Have try and get like this

img A img B
img 1
img 2

I want to get below table

img A img B
img 1 img 2

Why doctrine update entities when no setter has been called and change has been made?

PHP 8.1
Symfony 5.4
Doctrine 2.10

I’m profiling a PHP command (with blackfire) with dummy code for testing :

class MyCommand extends Command
{
    ...

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $query = $this->entityManager->createQuery(
            "SELECT t from AppEntityMyEntity t"
        );

        $query->setMaxResults(20);
        $i = 0;

        foreach ($query->getResult() as $transaction) {
            $i++;
        }
        
        $output->writeln($i);

        $this->entityManager->flush();

        return self::SUCCESS;
  }
  ...
}

So as you can see, no change made, no setter called.

But when I profile my command, I can see that doctrine made as many updates as there are entities :
Blackfire profiling output

It seems really unecessary, do you know what configuration could be causing this ?

Insert stament do not insert values in mysql table using pdo

I am new to pdo, and i wat to create a registration form all the code works including select qury but when i try to insert values to mysql I donot get any error but pdo insert do not insert any values in myaql table and always returns 0 rows insertd
`

<?php
function reg($err)
{
  global $pdo_conn;
  $fname = $err;
  $tab = 'user_details';
  $name = filter_var(strtoupper($_POST['name']), FILTER_SANITIZE_STRING);
  $cc_code = filter_var($_POST['cc_code'], FILTER_SANITIZE_NUMBER_INT);
  $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  $key =  password_hash($_POST['key'], PASSWORD_DEFAULT);
  $lvl = 1;
  $date = date("Y-m-d");
  $reg_chk_stmt = 'SELECT * FROM '.$tab. ' WHERE email = :email';
  $reg_chk_qry = $pdo_conn->prepare($reg_chk_stmt);
  $reg_chk_qry->bindParam(':email', $email);
  $reg_chk_qry->execute();
  $reg_chk_rows = $reg_chk_qry->rowCount();
  if ($cc_code != $fname) {
    $err_1 = 'Your firm is not autorized';
  }else {
    //$err_1 = 'your firm is authorized';
    if ($reg_chk_rows != 0) {
      $err_1 = 'email is alredy registerd';
    }else{
      try{
        $reg_ins_stmt = "INSERT INTO " .$tab. " (name, email, pass, firm, lvl, created_on) VALUES (:name, :email, :pass, :firm, :lvl, :created_on)";
        $reg_ins_qry = $pdo_conn->prepare($reg_ins_stmt);
        $reg_ins_qry->bindValue(':name', $name, PDO::PARAM_STR);
        $reg_ins_qry->bindValue(':email', $email, PDO::PARAM_STR);
        $reg_ins_qry->bindValue(':pass', $key, PDO::PARAM_STR);
        $reg_ins_qry->bindValue(':firm', $cc_code, PDO::PARAM_INT);
        $reg_ins_qry->bindValue(':lvl', $lvl, PDO::PARAM_INT);
        $reg_ins_qry->bindValue(':created_on', $created_on, PDO::PARAM_STR);
        $reg_ins_echo = $reg_ins_qry;
        $reg_ins_qry->execute();
        }catch(PDOException $error){
          $err_1 = $error->getMessage();
        }
      $reg_ins_rows = $reg_ins_qry->rowCount();
      if ($reg_ins_rows != 0) {
        $err_1 = $reg_ins_rows;
      }else {
        $err_1 = $reg_ins_rows . $reg_ins_qry;
      }
    }
  }
  $reg_chk_qry = NULL;
  $reg_ins_qry = NULL;
  return $err_1;
}
define('db_host','localhost');
define('db_user','dbuser');
define('db_pass','dbpass');
define('db_name','dbname');
// Establish database connection.
  try
{
$pdo_conn = new PDO("mysql:host=".db_host.";dbname=".db_name,
db_user, db_pass,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
//echo "pdo connection works";
}
catch (PDOException $error)
{
exit("Error: could not connect to database");
}
$fname = 21828;
$error = reg($fname);
$header = 'Location: https://xyz.zy/index.php' . '?keyin_err=' . $error;
header($header);
 ?>

`

I tryed to run above code i donot get any error but my code donot insert any valuses to my mysql table

I need to choose between image and video from database with php (if – else) [closed]

I’m pulling pictures and videos from database. I want to create an if else with php and hide normal photo if there is video.

<?php
if (count($maschine->Bild)) {
  echo "<img src='<?php echo $lBild; ?>' class='latest-img' style='object-fit:scale-down; height: 100%' />";
} 
else
{
  echo "<video width='100%' controls autoplay muted loop src='<?php echo $lBild; ?>'></video>";            
}

?>

Doctrine State management

Is it possible to save the state of the database at given time in doctrine?

Why? well for example lets say I seed a database with Products table and Customer Table and then we have 1 Products record and 1 Customer record. Then I do some crud activity on the Products table that I now have 3 Products and changed the name of the original first Product. But now for the next test or time I want to reset to state back to where I was done seeding So then when I start doing the Customer testing I start with a Fresh database with out having to reseed the database?

Can I for example hook into the even system and see which products gets created and then fix the database after or some kind of back up and reset it towards that state?

Any advice will be appreciated

Quick note I dont have access towards PHPunit

check if value exists in multidimensional array and find index

I have an multidimensional array like this:

$downloadArray = [
  "downloads1" => ["downloadnaam" => "fdgssgsfg"],
  "downloads2" => ["downloadnaam" => "eyetyy"],
];

I need to check if the value eyetyy exists in this array under the key downloadnaam
Then I need to find the index of this value and remove it from the array.

The expected result:

$downloadArray = [
  "downloads1" => ["downloadnaam" => "fdgssgsfg"]
];

I tried this:

$index = array_search($download->name, array_column($downloadArray, 'downloadnaam'));
if ($index !== null)
{
   unset($downloadArray[$index]);
   die("found index: " . $index);
}

$download->name contains 'eyetyy'
$downloadArray is my array
But it always dies and doesn’t show any index on screen.
Can anyone help me?