Structuring one sql query above another in php

Im trying to structure more than one sql query over another so that I could produce the result in a pdf (using tcpdf). I cant use joins in this case because i have 3 columns(in the table i want to produce) that have different where conditions for each. Ive tried putting one query over the other but get the following error.

Fatal error: Uncaught Error: Call to undefined method mysqli::query1() in C

This is my erroneous code. Could someone please show me where ive gone wrong with structuring this?

function fetch_data()  

 {  
      $output = '';  
      include ('dbcon.php'); 

      $query1 = $conn-> query1("SELECT empfname, emplname from employee");
      while ($row1 = $query1 -> fetch_array()){

         $query = $conn -> query("SELECT count(1) from tasks WHERE pf = '1' and stats ='0' ");  
         while($row = $query -> fetch_array())  
         {  

            $number = $row[0];     
            $output .= '<tr>  
                            
                          <td>'.$number.'</td>  
                          <td>'.$row1["empfname"].'</td>
                          <td>'.$row1["emplname"].'</td>
                 </tr>  
                          ';  
          } 
     } 
 return $output;  
 }

Filter nested array by value existing an other array

I have the nested array ot transactions. One transaction has those elements 0=TransId, 1=ClientId, 2 = TransactionType, 4=Quantity:

$transactions = [
    [1,'CLIENT1','BUY',45.12],
    [7,'CLIENT2','BUY',25.15],
    [11,'CLIENT3','SELL',784.25],
    [14,'CLIENT1','SELL',7.04],
    [19,'CLIENT1','BUY',21.12],
    [21,'CLIENT2','SELL',14.12],
    [27,'CLIENT3','BUY',15.27]
];

I have another array, which represents Ids of VIP clients:

$vipClients = ['CLIENT2','CLIENT3'];

I am able to compute an array with transactions of VIP clients by means of foreach loop:

$vipTransactions = [];
foreach ($transactions as $transaction) {
    if (in_array($transaction[1], $vipClients)) {
        array_push($vipTransactions, $transaction);
    }
}
var_dump($vipTransactions);

I prefer to use php array functions instead of a foreach loop. Can you suggest me, how to filter nested array and value of nested segment, which will be filtered by existing value in other array? I want to use only array functions, not loops.

How to submit answers of a Javascript Quiz? [closed]

The quiz is written using vanilla Javascript and HTML:

<div class="quiz-container" id="quiz">
    <div class="quiz-header">
      <p>Please make sure to <a href="#">read the rules</a></p>
      <h1>Quiz</p>
      <h2 id="question">Question Text</h2>
      <ul>
        <li>
          <input type="radio" name="answer" id="a" class="answer">
          <label for="a" id="a_text">Answer</label>
        </li>
        <li>
          <input type="radio" name="answer" id="b" class="answer">
          <label for="b" id="b_text">Answer</label>
        </li>
        <li>
          <input type="radio" name="answer" id="c" class="answer">
          <label for="c" id="c_text">Answer</label>
        </li>
        <li>
          <input type="radio" name="answer" id="d" class="answer">
          <label for="d" id="d_text">Answer</label>
        </li>
      </ul>
    </div>
    <button id="submit">Next</button>
  </div>

At the end of the quiz, the results are shows to the user:

submitBtn.addEventListener('click', () => {
const answer = getSelected()
if(answer) {
   if(answer === quizData[currentQuiz].correct) {
       score++
   }
   currentQuiz++
   if(currentQuiz < quizData.length) {
       loadQuiz()
   } else {
    quiz.innerHTML = `
    <h2>You answered ${score}/${quizData.length} questions correctly</h2> 
    <input class="btn" type="button" onclick="window.open('mailto:email@email');" value="Submit results" />
    `
   }
}

What is the best way to possibly submit these answers to a backend? I know Javascript can’t blind submit results using mailto: as it’s client side, so any suggestions would be amazing.

How to querry between dates

I want my php code check if person is on leave between two dates and capture an error that the person is already on leave.

I have tried:

$check = "SELECT * FROM `tblleaves` where 'FromDate' BETWEEN $fromdate and $todate   and empid = '$session_id' ";

how to write to a file in php?

so I’m new to php and I’m working on a school task. Its a simple form that will take the inputs and write it to a txt file. But for me it doesn’t work. I tried to make a test version to see where the problem is and the error i get is 405 method not allowed. I have used fopen and fwrite too but they dont work too.

enter image description here

Here is my html code

<!DOCTYPE html>
<html lang="No">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index1</title>
</head>
<body>
 
  <form method="post" action="test21.php" name="myForm">
    klassekode <input type="text" id="klassekode" name="klassekode" required />
    <input type="submit" value="Fortsett" id="fortsett" name="fortsett" />
  </form>
 <a href="klasse.txt">Vis  klasser </a> 
               
</body> 
</html>


and my very simplified php code that i used to test test21.php

<?php
file_put_contents("klasse.txt", "test");
?>

laravel select2 installed but not working

I am creating a laravel crud application and im using select2 plugin. I have installed it with bower and perform the same steps as mentioned in the documentation.
but the css is different and I can’t even select.
bower.json:

{
  "name": "select2",
  "description": "Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.",
  "main": [
    "dist/js/select2.js",
    "src/scss/core.scss"
  ],
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "[email protected]:select2/select2.git"
  },
  "homepage": "https://github.com/ivaynberg/select2",
  "version": "4.0.13",
  "_release": "4.0.13",
  "_resolution": {
    "type": "version",
    "tag": "4.0.13",
    "commit": "45f2b83ceed5231afa7b3d5b12b58ad335edd82e"
  },
  "_source": "https://github.com/ivaynberg/select2.git",
  "_target": "^4.0.13",
  "_originalSource": "select2",
  "_direct": true
}

the code:

<div class="form-group">
    <label for="name">{{('tags')}}</label>
    <select name="tag_id" class="js-example-basic-multiple w-100" multiple="multiple">
        @foreach($tags as $tag)
            <option value=" {{$tag->id}}">{{$tag->name}}</option>
        @endforeach
    </select>
</div>

js script:

<script>
    $(document).ready(function() {
        $('.js-example-basic-multiple').select2();
    });
</script>

enter image description here

how to loop through different level of multidimensional array in php using foreach loop

there is an inner array at the 0 index of very first array. how do I loop through this array by using foreach loop? only ali has one more array.

            <?php
            $marks=[
                "ali" => ["physics" => 55, "chemistry" => array(12, "practical"=>45),"math"=>18],
                "salman" => ["physics" => 34, "chemistry"=>44,"math"=>68],
                "Mohan" => ["physics" => 98, "chemistry"=>40,"math"=>89]
            ];
            foreach($marks as $key => $val)
            {
                echo "$key ";
                    foreach($val as $val2) 
                            {
                                echo " $val2 ";
                                // foreach($val2 as $InVal){
                                //     echo $InVal;
                                // }
                            }
                            echo "<br>";
            }
            ?>

There is no active transaction’

having problems with this function wipe_data

this wipe_data function my DB cleanup and admin data inserting
but this function shows error:

There is no active transaction

This is my code:

 function wipe_data() {
     DB::beginTransaction();
     $adminData = User::where('role', 'admin')->first();  
    try {
        User::truncate();
        User_details::truncate();
        User_kyc::truncate();
        Token::truncate();`enter code here`
        $auto_id = date('Y');
        DB::statement("ALTER TABLE ls_users AUTO_INCREMENT = $auto_id");
        $admin = new User();
        $admin->username = $adminData->username;
        $admin->email = $adminData->email;
        $admin->password = $adminData->password;
        $admin->role = $adminData->role;
        $admin->save();
        $user_id = User::where('role', 'admin')->value('id');
        DB::commit();
    } catch (Exception $ex) {
        DB::rollback();
        return false;
    }
    return true;
}

Woocommerce registration form doesn’t submit on PHP 8.0 version

I have custom Woocommerce registration form that works fine on PHP 7.3 version, but not on 8.0. My validation fields still work fine but when you click submit – nothing happens.

Could someone tell me if anything has changed between these two PHP versions (class or function names) in order to bring it up to 8.0?

Here are my functions that work on 7.3:

add_action( 'show_user_profile', 'display_user_custom_hash' );
add_action( 'edit_user_profile', 'display_user_custom_hash' );

function display_user_custom_hash( $user ) { ?>
    <h3>Additional Fields</h3>
    <table class="form-table">
        <tr>
            <th><label>Suit Number</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'suit_number', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
    <table class="form-table">
        <tr>
            <th><label>Vat Number</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'vat_number', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
    <table class="form-table">
        <tr>
            <th><label>License Status</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'license_status', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
    <table class="form-table">
        <tr>
            <th><label>License Numnber</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'license_number', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
    <table class="form-table">
        <tr>
            <th><label>License Expiry</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'license_expiry', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>

    <table class="form-table">
        <tr>
            <th><label>Profession</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'profession', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
    <table class="form-table">
        <tr>
            <th><label>Speciality</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'speciality', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>

    <table class="form-table">
        <tr>
            <th><label>Medical professional name</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'medical_professional_name', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>

    <table class="form-table">
        <tr>
            <th><label>Fax</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'fax', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
 <table class="form-table">
        <tr>
            <th><label>Phone</label></th>
            <td><input type="text" value="<?php echo get_user_meta( $user->ID, 'reg_phone', true ); ?>" class="regular-text" readonly=readonly /></td>
        </tr>
    </table>
    <?php
}

And my form:

<section id="custom-registration-tabs">
  <form id="user-custom-register-form" class="woocommerce-form woocommerce-form-register register my-0 form-horizontal" <?php do_action( 'woocommerce_register_form_tag' ); ?>>
      <div class="all-steps" id="all-steps"> <span class="step"></span> <span class="step"></span> <span class="step"></span> <span class="step"></span> </div>
      <?php wp_nonce_field('user_register', 'reg_user_nonce', true, true ); ?>
      <input type="hidden" name="action" value="register_user" >

      <!-- Step 1 -->
      <fieldset id="crf-step1" class="crf-tab">
        <div class=" form-group row">
          <?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
            <div class="col-md-12">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="username" id="reg_username" autocomplete="username" value="<?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?>" placeholder="Username" required="required"  />
            </div>
          <?php endif; ?>
        </div>

        <div class=" form-group row">
          <div class="col-md-12">
            <input type="email" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="email" id="reg_email" autocomplete="email" value="<?php echo ( ! empty( $_POST['email'] ) ) ? esc_attr( wp_unslash( $_POST['email'] ) ) : ''; ?>" placeholder="Email address" required />
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-12">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="reg_phone" id="reg_phone" autocomplete="reg_phone" value="<?php echo ( ! empty( $_POST['reg_phone'] ) ) ? esc_attr( wp_unslash( $_POST['reg_phone'] ) ) : ''; ?>" placeholder="Phone Number" required="required"  />
          </div>
          
          <div class="col-md-12">
              <select class="hear_about_us" name="hear_about_us" id="hear_about_us" style="background-image: url('<?php echo site_url(); ?>/wp-content/uploads/2021/08/Polygon-5.png');">
                  <option value="0">How did you hear about us?</option>
                  <option value="Friends">Friends</option>
                  <option value="Website">Website</option>
                  <option value="Social Media">Social Media</option>
                  <option value="Other">Other</option>
              </select>
          </div>
          <div class="col-md-12">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="fax" id="fax" autocomplete="fax" value="<?php echo ( ! empty( $_POST['fax'] ) ) ? esc_attr( wp_unslash( $_POST['fax'] ) ) : ''; ?>" placeholder="Fax"/>
          </div>
          
        </div>

        <div class=" form-group row">
          <div class="col-md-12">
            <?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?>

              <input type="password" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="password" id="reg_password" autocomplete="new-password" placeholder="Password" required />

            <?php else : ?>

              <p><?php esc_html_e( 'A password will be sent to your email address.', 'woocommerce' ); ?></p>

            <?php endif; ?>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-12">
            <button type="button" class="btn btn-primary btn-block next-step" data-toggle="1">Next </button>
          </div>
        </div>

      </fieldset>



      <!-- Step 2 -->
      <fieldset id="crf-step2" class="crf-tab">

        <div class=" form-group row" style="display: none;">
          <div class="col-md-6">
            <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="first_name" id="reg_first_name" autocomplete="first_name" value="<?php echo ( ! empty( $_POST['first_name'] ) ) ? esc_attr( wp_unslash( $_POST['first_name'] ) ) : ''; ?>" placeholder="First Name"/><?php // @codingStandardsIgnoreLine ?>
          </div>
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="last_name" id="reg_last_name" autocomplete="last_name" value="<?php echo ( ! empty( $_POST['last_name'] ) ) ? esc_attr( wp_unslash( $_POST['last_name'] ) ) : ''; ?>" placeholder="Last Name"/><?php // @codingStandardsIgnoreLine ?>
          </div>
        </div>

        <div class="form-group row">
          <div class="col-md-12">
            <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_address" id="reg_address" autocomplete="reg_address" value="<?php echo ( ! empty( $_POST['billing_address'] ) ) ? esc_attr( wp_unslash( $_POST['billing_address'] ) ) : ''; ?>" placeholder="Address/ P.O box, company name, c/o"/><?php // @codingStandardsIgnoreLine ?>
          </div>
        </div>
        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_city" id="reg_city" autocomplete="billing_city" value="<?php echo ( ! empty( $_POST['billing_city'] ) ) ? esc_attr( wp_unslash( $_POST['billing_city'] ) ) : ''; ?>" placeholder="City"/>
          </div>
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="billing_zipcode" id="reg_zipcode" autocomplete="zip_code" value="<?php echo ( ! empty( $_POST['billing_zipcode'] ) ) ? esc_attr( wp_unslash( $_POST['billig_zipcode'] ) ) : ''; ?>" placeholder="Zip/ Postal code"/>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-6">

            <?php
            global $woocommerce;
            $countries_obj   = new WC_Countries();
            $countries   = $countries_obj->__get('countries');
            $default_country = $countries_obj->get_base_country();
            $default_county_states = $countries_obj->get_states( $default_country );

            woocommerce_form_field('mspa_country_field', array(
              'type'       => 'country',
              'class'      => array( 'chzn-drop' ),
              'id'         => 'mspa_country_field',
              'placeholder'    => __('Select a country'),
              'options'    => $countries
              )
            );
            ?>
          </div>

          <div class="col-md-6">
            <?php
            $default_county_states = $countries_obj->get_states( $default_country );
            woocommerce_form_field('mspa_state_field', array(
                'type'       => 'state',
                'class'      => array( 'chzn-drop' ),
                'id'         => 'mspa_state_field',
                'placeholder'    => __('Select a State'),
                'options'   => $default_county_states
                )
            );
            ?>
          </div>
        </div>

        <div class="form-group row">
          <div class="col-md-12">
            <button type="button" class="btn btn-primary next-step" data-toggle="2">Next </button>
          </div>
          <div class="col-md-12 text-center">
            <button type="button" class="btn1 btn-default1 previous-step" data-toggle="2">Previous </button>
          </div>
        </div>

      </fieldset>



      <!-- Step 3 -->
      <fieldset id="crf-step3" class="crf-tab">

        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="contact_name" id="contact_name" autocomplete="contact_name" value="<?php echo ( ! empty( $_POST['contact_name'] ) ) ? esc_attr( wp_unslash( $_POST['contact_name'] ) ) : ''; ?>" placeholder="Contact name"/>
          </div>
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="secondary_phone_number" id="secondary_phone_number" autocomplete="secondary_phone_number" value="<?php echo ( ! empty( $_POST['secondary_phone_number'] ) ) ? esc_attr( wp_unslash( $_POST['secondary_phone_number'] ) ) : ''; ?>" placeholder="Phone number"/>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="vat_number" id="vat_number" autocomplete="vat_number" value="<?php echo ( ! empty( $_POST['vat_number'] ) ) ? esc_attr( wp_unslash( $_POST['vat_number'] ) ) : ''; ?>" placeholder="Vat number"/>
          </div>
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="suit_number" id="suit_number" autocomplete="suit_number" value="<?php echo ( ! empty( $_POST['suit_number'] ) ) ? esc_attr( wp_unslash( $_POST['suit_number'] ) ) : ''; ?>" placeholder="Suit/Unit Number"/>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="license_status" id="license_status" autocomplete="license_status" value="<?php echo ( ! empty( $_POST['license_status'] ) ) ? esc_attr( wp_unslash( $_POST['license_status'] ) ) : ''; ?>" placeholder="License Status"/>
          </div>
          <div class="col-md-6">
              <input type="date" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="license_expiry" id="license_expiry" autocomplete="license_expiry" value="<?php echo ( ! empty( $_POST['license_expiry'] ) ) ? esc_attr( wp_unslash( $_POST['license_expiry'] ) ) : ''; ?>" placeholder="License Expiry Date"/>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="license_number" id="license_number" autocomplete="license_number" value="<?php echo ( ! empty( $_POST['license_number'] ) ) ? esc_attr( wp_unslash( $_POST['license_number'] ) ) : ''; ?>" placeholder="License Number"/>
          </div>
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="profession" id="profession" autocomplete="profession" value="<?php echo ( ! empty( $_POST['profession'] ) ) ? esc_attr( wp_unslash( $_POST['profession'] ) ) : ''; ?>" placeholder="Profession"/>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="speciality" id="speciality" autocomplete="speciality" value="<?php echo ( ! empty( $_POST['speciality'] ) ) ? esc_attr( wp_unslash( $_POST['speciality'] ) ) : ''; ?>" placeholder="Speciality"/>
          </div>
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="medical_professional_name" id="medical_prodessional_name" autocomplete="medical_professional_name" value="<?php echo ( ! empty( $_POST['medical_professional_name'] ) ) ? esc_attr( wp_unslash( $_POST['medical_professional_name'] ) ) : ''; ?>" placeholder="Medical Professional Name"/>
          </div>
        </div>

        <div class=" form-group row">
          <div class="col-md-6">
              <input type="text" class="woocommerce-Input woocommerce-Input--text input-text form-control" name="cell_no" id="cell_no" autocomplete="cell_no" value="<?php echo ( ! empty( $_POST['cell_no'] ) ) ? esc_attr( wp_unslash( $_POST['cell_no'] ) ) : ''; ?>" placeholder="Cell Number"/>
          </div>
          
        </div>

        <div class=" form-group row">
          <div class="col-md-12">
            <button type="button" class="btn btn-primary next-step" data-toggle="3">Next </button>
          </div>
          <div class="col-md-12 text-center">
            <button type="button" class="btn1 btn-default1 previous-step" data-toggle="3">Previous </button>
          </div>
        </div>


      </fieldset>


      <!-- Step 4 -->
      <fieldset id="crf-step4" class="crf-tab">
        <div class=" form-group row">
          <div class="col-md-12">
            <div id="terms-wrapper">
              <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
                <input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms_condition" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms_condition'] ) ), true ); ?> id="terms_condition" /> <span><?php printf( __( 'I have read and understood the <a href="%s" target="_blank" class="woocommerce-terms-and-conditions-link">terms and conditions</a> set out in the agreement (including schedule "a") as found here and agree, on behalf of myself, my heirs, successors, administrators and assigns, to be bound by these terms and conditions.', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms_condition' ) ) ); ?></span> <span class="required">*</span>
              </label>
              <input type="hidden" name="terms-field" value="1" />

              <p>
                <button type="button" class="btn btn-default previous-step" data-toggle="4">Previous </button>
                <button id="reg-form-submit" type="button" class="woocommerce-Button woocommerce-button button woocommerce-form-register__submit reg-form-submit btn btn-primary next-step" name="register" value="<?php esc_attr_e( 'SUBMIT', 'woocommerce' ); ?>"><?php esc_html_e( 'SUBMIT', 'woocommerce' ); ?></button>
              </p>
            </div>

            <div class="thanks-message text-center" id="thanks-message">
            </div>
          </div>
        </div>
      </fieldset>

      <p class="status"></p>
      <?php wp_nonce_field( 'woocommerce-register', 'woocommerce-register-nonce' ); ?>
      <input type="hidden" name="current_tab" value="1" id="current_tab" >

  </form>
</section>

How to solve Undefined array key “userid”? [closed]

I am getting Undefined array key “userid” error but user id field exist in database I am trying to get userid by following is my function where I am trying to get user id

 function checkAuthStatusAndReturnUserID($writeDB) {

  if(!isset($_SERVER['HTTP_AUTHORIZATION']) || strlen($_SERVER['HTTP_AUTHORIZATION']) < 1) {

    $message = null;

    if(!isset($_SERVER['HTTP_AUTHORIZATION'])) {
      $message = "Access token is missing from the header";
    } else {
      if(strlen($_SERVER['HTTP_AUTHORIZATION']) < 1) {
          $message = "Access token cannot be blank";
      }
    }

    sendResponse(401, false, $message);
  }

  // get supplied access token from authorisation header - used for delete (log out) and patch (refresh)
  $accesstoken = $_SERVER['HTTP_AUTHORIZATION'];

  try {
    // create db query to check access token is equal to the one provided
    $query = $writeDB->prepare('select adminsession.userid as usrid, accesstokenexpiry  from adminsession, admin where adminsession.userid = admin.id and accesstoken = :accesstoken');
    $query->bindParam(':accesstoken', $accesstoken, PDO::PARAM_STR);
    $query->execute();


    $rowCount = $query->rowCount();

    if($rowCount === 0) {
      // send json error response using function for unsuccessful log out response
      sendResponse(401, false, "Invalid access token $accesstoken");
    }


    $row = $query->fetch(PDO::FETCH_ASSOC);


    $returned_userid = $row['userid'];
    $returned_accesstokenexpiry = $row['accesstokenexpiry'];

you can see userid columns in database

you can see in the above image userid column exists

Why this return me ‘string given’ when the only Id pass is an int

I’m new on symfony and need help

When i’m running ‘console debug:event’ I got this error message :

 AppEventListenerReservationEventSubscriber::__construct(): Argument #3 ($id) must be of type int, string given, called in /Applica  
  tions/MAMP/htdocs/E-STock/E-STock_v6/var/cache/dev/ContainerTiaj2qn/getReservationEventSubscriberService.php on line 22

The problem is that I don’t understand how to fix it.
Even I’m not sur to really understand the problem ^^

this is my code :

ReservationEventSubscriber :

class ReservationEventSubscriber implements EventSubscriberInterface
{

    private $manager;
    private int $id;


    public function __construct(EntityManagerInterface $manager, TokenStorageInterface $tokenStorage, int $pieceId)
    {
        
        $this->manager = $manager;
        $this->tokenStorage = $tokenStorage;
        $this->id = $pieceId;
    }

I’ve bind my “pieceId” here on ‘service.yaml’

parameters:
      id: 'secret'

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        bind:
           int $pieceId: '%id%'

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
        

PHP contants: defined(): Argument #1 ($constant_name) must be of type string, array given

I am using PHP 8.1. I have defined a MY_CONSTANT constant and I want to check if it is available.
Instead of isset() I am using the intended function defined().

if (defined(MY_CONSTANT) && is_array(MY_CONSTANT)) {
    // do stuff
}

The constant MY_CONSTANT is an array and I get the following error:

defined(): Argument #1 ($constant_name) must be of type string, array given

I don’t understand why PHP expects a value of type string when I just want to check the availability of the constant, not its type.

tree traversal to nth node

I have a multidimensional array.

$tree= [
    "wood"=> [
      "segun",
      "koroi",
      "karosin"
    ],
    "food"=> [
        'grain',
        "vegetable"=> [
            "potato",
            "tomato"=>[
                "small"=>["cherri","local"],
                "big"=>["green","red"]
            ],
            "radish"
        ],
        "fruits"=> [
            "mango"=>[
              "lengra",
              "amrupali",
              "fozli",
                "him sagar"
            ],
            "jak fruits"
        ]
    ],
    "medicine"=> [
        "nim",
        "arjun",
        "amla"
    ],
    "oxygen",
    "computer"

];

I am using this code to show

function treeView($tree){
        $markup='';

        foreach ($tree as $key=>$value){

            $markup.= '<li>'. (is_array($value) ? $key. treeView($value) : $value) .'</li>';

        }
        return "<ul>".$markup."</ul>";
    }

I want to show upto 2 nodes of each element. This is not fixed, it can be nth nodes depends on user input. I am not getting it how to solve this.