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.

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 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");
?>

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.

How can I add an extra block in Laravel

I need to add canonical URLs to the pages of my Laravel project as in the example below.

example:
For the about page for example it should print out <link rel="canonical" href="https://omnicourse.io/about">

In order to add them to my pages, I need to add them inside the <head> blocks. However, the <head> blocks of the pages come from layoutsapp.blade.php and therefore they all get the same blocks. As an example, I leave an index.blade.php and app.blade.php file below. How can I add a separate <head> block to the example index.blade.php file I gave.

index.blade.php

@extends('layouts.app')

@section('content')
    <div class="bg-pippin p-12 rounded-t-2xl relative">
        <div class="lg:w-3/5 w-full">
            <h2 class="lg:text-8xl text-4xl font-argent">Our mission</h2>
            <p class="my-5">Giving knowledge a voice</p>
            <h5 class="lg:text-3xl text-xl">Omnicourse believes audio makes it easier for experts to bring their knowledge to life and that the world needs a simple platform where expertise can be shared.</h5>
        </div>
        <img src="{{ asset('assets/images/mockup-1.png') }}" class="lg:block hidden absolute right-16 top-10 w-72" alt="">
    </div>
    <div class="bg-soft-blue p-12">
        <div class="lg:w-3/5 w-full">
            <h2 class="lg:text-8xl text-4xl font-argent">Our intent</h2>
            <ul class="intent-list mt-5">
                <li><h5 class="lg:text-3xl text-xl">Simplifying eLearning</h5></li>
                <li><h5 class="lg:text-3xl text-xl">Empowering teaching</h5></li>
                <li><h5 class="lg:text-3xl text-xl">Bringing knowledge to life</h5></li>
            </ul>
        </div>
    </div>

    <div class="bg-soft-text text-white p-12 ">
        <div>
            <h2 class="lg:text-8xl text-4xl font-argent">Our name</h2>
            <h5 class="text-3xl my-5">According to Urban Dictionary, 'Omnicourse' is</h5>
            <ul class="list-decimal ml-8">
                <li class="lg:text-2xl text-xl font-light"><h5>A powerfully connecting experience.</h5></li>
                <li class="lg:text-2xl text-xl font-light"><h5>To experience someone in a complete and utterly all encompassing fashion.</h5></li>
                <li class="lg:text-2xl text-xl font-light"><h5>To reciprocally share ones physicality, feelings, thoughts, memories & more.</h5></li>
            </ul>
            <h5 class="lg:text-3xl text-xl my-5">That about sums us up.</h5>
        </div>
    </div>

    <div class="bg-pippin p-12 rounded-b-2xl">
        <h2 class="lg:text-8xl text-4xl font-argent mb-8">Create. Share. Learn.</h2>
        <div class="grid grid-rows-1 lg:grid-cols-2 grid-cols-1 lg:gap-9 gap-4 text-xl leading-7">
            <div>
                <p class="mb-7">We all spend too much time staring at screens. Omnicourse is an accessible way to learn. You don't need to focus on your screen; you don't have to leave everything aside; you need to put on your headphones and listen to learn ―while doing whatever you want to be doing.</p>
                <p class="mb-7">Omnicourse enables learners to step away from the screen and consume without distractions. Audio courses are great for commuting, running, or doing housework.</p>
                <p class="mb-7">With Omnicourse, you can turn your spare listening time into productive learning time.</p>
                <p class="mb-7">We provide a solution to the knowledge gap; you learn at your own pace. </p>
            </div>
            <div>
                <p class="mb-7">eLearning as an industry is changing, and creators feel that change. Without messy video editing and technical expertise, they want a platform to share what they know conveniently. </p>
                <p class="mb-7">Omnicourse provides creators with all the tools and helps them share what they know on the Omnicourse platform. </p>
            </div>
        </div>
    </div>

@endsection

app.blade.php

<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="{{ asset('assets/css/style.css')}}" rel="stylesheet" />
    <title>omnicourse ― Grow your skills with audio courses</title>
    <meta name="title" content="omnicourse ― Grow your skills with audio courses">
    <meta name="description" content="omnicourse is a subscription-based capsule-sized audio course platform for mobile where lecturers can get paid by the minutes listened.">
    <meta property="og:type" content="website">
    <meta property="og:url" content="https://omnicourse.io/">
    <meta property="og:title" content="omnicourse ― Grow your skills with audio courses">
    <meta property="og:description" content="omnicourse is a subscription-based capsule-sized audio course platform for mobile where lecturers can get paid by the minutes listened.">
    <meta property="og:image" content="@yield('og_image', asset('assets/images/logo-circle.jpg'))">
    <meta property="twitter:card" content="summary_large_image">
    <meta property="twitter:url" content="https://omnicourse.io/">
    <meta property="twitter:title" content="omnicourse ― Grow your skills with audio courses">
    <meta property="twitter:description" content="omnicourse is a subscription-based capsule-sized audio course platform for mobile where lecturers can get paid by the minutes listened.">
    <meta property="twitter:image" content="@yield('twitter_image', asset('assets/images/logo-circle.jpg'))">
    <link rel="apple-touch-icon" sizes="180x180" href="{{ asset('assets/favicon/apple-touch-icon.png')}}">
    <link rel="icon" type="image/png" sizes="32x32" href="{{ asset('assets/favicon/favicon-32x32.png')}}">
    <link rel="icon" type="image/png" sizes="16x16" href="{{ asset('assets/favicon/favicon-16x16.png')}}">
    <link rel="manifest" href="{{ asset('assets/favicon/site.webmanifest')}}">
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
                new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
            j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
            'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
        })(window,document,'script','dataLayer','GTM-KDBG3WH');</script>
</head>
<body>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KDBG3WH" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script type="text/javascript">
    function initDesk360Chat() {
        window.desk360Chat.init({
            token: "cZteL2U9khzVrahABDBS4NSLNXGixkfED9SDLAcDrGjuRJky88VYdKW11CBH1aJ6UCQggMGPSURO2OkG",
            host: "https://omnicourse.desk360.com/"
        });
    }
    function initialize(t,i){var e,a=btoa((new Date).toDateString()).toLowerCase();t.getElementById(i)?initDesk360Chat():((e=t.createElement("script")).id=i,e.async=!0,e.src="https://omnicourse.desk360.com/widgets/chat/sdk.js?".concat(a),e.onload=initDesk360Chat,t.head.appendChild(e))}function initiateCall(){initialize(document,"desk360chat-js-sdk")}window.addEventListener?window.addEventListener("load",initiateCall,!1):window.attachEvent("load",initiateCall,!1);
</script>

<div class="container mx-auto px-4 xl:px-0">
    <header class="flex justify-between items-center py-6">
        <a href="/">
            <img src="{{ asset('assets/images/logo.svg')}}" alt="omnicourse ― Grow your skills with audio courses">
        </a>
        <nav class="lg:flex hidden">
            <ul class="flex">
                <li><a href="/about" class="mx-3 text-gray-500">About</a></li>
                <li><a href="/faq" class="mx-3 text-gray-500">FAQ</a></li>
                <li><a href="/creators" class="mx-2 text-almost-black font-semibold">Become a Creator</a></li>
                <li><a href="https://creator.omnicourse.io/" target="_blank" class="mx-2 text-almost-black font-semibold">Creator Center</a></li>
            </ul>
        </nav>
        <button class="flex lg:hidden mobile-nav-btn">
            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-menu-2" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" stroke="#192648" fill="none" stroke-linecap="round" stroke-linejoin="round">
                <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                <line x1="4" y1="6" x2="20" y2="6" />
                <line x1="4" y1="12" x2="20" y2="12" />
                <line x1="4" y1="18" x2="20" y2="18" />
            </svg>
        </button>
    </header>
    @if($errors->any())
        {!! implode('', $errors->all('<div class="mb-4 bg-lust border border-lust-400 text-white px-4 py-3 rounded relative" role="alert"><img src="'.asset("assets/images/warning_error.png").'" width="40" height="40"><br><strong class="font-bold">:message</strong></div>'))  !!}
    @endif
    @yield('content')
    <footer class="border-t border-soft-text mt-16 py-16 grid grid-rows-1 lg:grid-cols-4 grid-cols-1">
        <div class="mb-2 md:mb-0">
            <h6 class="font-semibold mb-2 md:mb-5">omnicourse</h6>
            <div class="flex flex-col">
                <a href="/about" class="text-sm mb-3 hover:text-lust">About omnicourse</a>
                <a href="https://creator.omnicourse.io/" target="_blank" class="text-sm mb-3 hover:text-lust">Creator Center </a>
                <a href="/identity" class="text-sm mb-3 hover:text-lust">Company Culture</a>
                <a href="/creators" class="text-sm mb-3 hover:text-lust">Become a Creator</a>
                <a href="/faq" class="text-sm mb-3 hover:text-lust">Frequently Asked Questions</a>
                <a href="/privacy-policy" class="text-sm mb-3 hover:text-lust">Privacy Policy</a>
                <a href="/terms-of-use" class="text-sm mb-3 hover:text-lust">Terms and Conditions</a>
            </div>
        </div>
        <div  class="mb-2 md:mb-0">
            <h6 class="font-semibold mb-2 md:mb-5">Social</h6>
            <div class="flex flex-col">
                <a href="https://www.linkedin.com/company/omnicourse/" target="_blank" class="text-sm mb-3 hover:text-lust">Linkedin</a>
                <a href="https://medium.com/@omnicourse" target="_blank" class="text-sm mb-3 hover:text-lust">Medium</a>
                <a href="https://www.instagram.com/omnicourse/" target="_blank" class="text-sm mb-3 hover:text-lust">Instagram</a>
                <a href="https://twitter.com/omnicourse/" target="_blank" class="text-sm mb-3 hover:text-lust">Twitter</a>
            </div>
        </div>
        <div  class="mb-4 md:mb-0">
            <h6 class="font-semibold mb-2 md:mb-5">Contact</h6>
            <a href="mailto:[email protected]" class="text-sm mb-3 hover:text-lust">[email protected]</a>
        </div>
        <div  class="mb-2 md:mb-0">
            <a href="https://omnicourse.io" class="mb-4 inline-block"><img src="{{ asset('assets/images/logo.svg') }}" style="height:25px" alt=""></a>
            <p class="text-sm mb-3">Copyright © 2022 Omnicourse, Inc.</p>
        </div>
    </footer>

</div>

<div class="fixed inset-0 overflow-hidden mobile-nav" aria-labelledby="slide-over-title" role="dialog" aria-modal="true">
    <div class="absolute inset-0 overflow-hidden mobile-nav__container">
        <div class="absolute inset-0 bg-gray-500 bg-opacity-75 transition-opacity " aria-hidden="true"></div>
        <div class="fixed inset-y-0 right-0 pl-10 max-w-full flex ">
            <div class="relative w-screen max-w-md">
                <div class="absolute top-0 left-0 -ml-8 pt-4 pr-2 flex sm:-ml-10 sm:pr-4">
                    <button type="button" class="mobile-nav__close rounded-md text-gray-300 hover:text-white focus:outline-none focus:ring-2 focus:ring-white">
                        <span class="sr-only">Close panel</span>
                        <svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                        </svg>
                    </button>
                </div>

                <div class="h-full flex flex-col py-6 bg-white shadow-xl overflow-y-scroll">
                    <div class="px-4 sm:px-6 border-b border-gray-300 pb-2">
                        <h2 class="text-lg font-medium text-gray-900" id="slide-over-title">
                            Menu
                        </h2>
                    </div>
                    <div class="mt-6 relative flex-1 px-4 sm:px-6">
                        <div class="absolute inset-0 px-4 sm:px-6">
                            <div class="h-full" aria-hidden="true">
                                <ul>
                                    <li class="my-4"><a href="/creators" class="text-base  text-almost-black font-medium">Become a Creator</a> </li>
                                    <li class="my-4"><a href="/content-upload" class="text-base  text-almost-black font-medium">Upload Content</a> </li>
                                    <li class="my-4"><a href="/about" class="text-base  text-gray-500 font-medium">About omnicourse</a> </li>
                                    <li class="my-4"><a href="/faq" class="text-base  text-gray-500 font-medium">Frequently Asked Questions</a> </li>
                                    <li class="my-4"><a href="https://www.linkedin.com/company/omnicourse/" class="text-base  text-gray-500 font-medium">LinkedIn</a> </li>
                                    <li class="my-4"><a href="https://medium.com/@omnicourse" class="text-base  text-gray-500 font-medium">Medium</a> </li>
                                    <li class="my-4"><a href="https://www.innstagram.com/omnicourse" class="text-base  text-gray-500 font-medium">Instagram</a> </li>
                                    <li class="my-4"><a href="https://www.twitter.com/omnicourse" class="text-base  text-gray-500 font-medium">Twitter</a> </li>
                                    <li class="my-4"><a href="/privacy-policy" class="text-base  text-gray-500 font-medium">Privacy Policy</a> </li>
                                    <li class="my-4"><a href="/terms-of-use" class="text-base  text-gray-500 font-medium">Terms Of Use</a> </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="{{ asset('assets/js/main.js') }}"></script>
<script>
        $(document).ready(function() {

            $('body').find('.upload-button-mini').each(function(){
                var $this = $(this);
                var completeClass = 'complate';
                var completeText = 'File Upload Completed.';
                var textItem = $this.find('#fileLimitOrText');

                $(this).find('[type="file"]').change(function(e) {
                    var fileName = this.files[0].name;
                    textItem.text(fileName);
                    $this.find('#uploadButtonTitle').text(completeText);
                    $this.addClass(completeClass);
                });
            });

            $('body').on('click', '.copybtn', function() {
                var copyText = $(this).data('copydata');
                console.log(copyText)
                /* Copy the text inside the text field */
                navigator.clipboard.writeText(copyText);

                /* Alert the copied text */
                alert("URL Copied: " + copyText);
            })
        })
</script>
</body>
</html>