idk what this php code does can someone tell me? [closed]

<?php

$seed = 'COPY_RAFFLE_SEED_HERE'; // Randomly generated seed [Seed:]
$raffle_id = 'COPY_RAFFLE_ID_HERE'; // Raffle ID [Raffle ID:]
$entries = 10; // Number of tickets [Entries count:]

/*
*
* Must +1 return value since it starts with 0
* 28 characters offset to get 4 characters from both hashes
*
*/

$randomNumber = (hexdec(substr(md5($seed) . md5($raffle_id), 28, 8)) % $entries)+1; // Must use +1 as it starts with 0
echo "Ticket with number #$randomNumber won";

apparently this is the code used for the giveaways, and i wanted to see how it works

I want to show more than one photo

<div class="col-lg-6">
    <div class="cz-product-gallery">
        <div class="cz-preview order-sm-2">
         <?php $i = 0;
         foreach ($prdGal as $galeri) {
            $i++; ?>
            <div class="cz-preview-item <?php if ($i == 1) {
                echo "active";
            } ?>" id="galeri_<?= $galeri->id ?>">
            <img class="cz-image-zoom" src="<?= base_url(firstGalleryItem($product->galeri_uniq)) ?>" data-zoom="<?= base_url(firstGalleryItem($product->galeri_uniq)) ?>" alt="<?= $product->urun_ad ?>">
            <div class="cz-image-zoom-pane"></div>
        </div>
    <?php } ?>
</div>

The above code is showing bigphotos

<div class="cz-thumblist order-sm-1">
    <?php $i = 0;
    foreach ($prdGal as $gal) {
        $i++; 
        $activeClass = $i == 1 ? "active" : "";?>
        <a class="cz-thumblist-item <?php if ($i == 1) {
            echo "active";
        } ?>" href="#galeri_<?= $gal->id ?>">
        <img src="<?= base_url(firstGalleryItem($product->galeri_uniq)) ?>"
        alt="<?= $product->urun_ad ?>">
    </a>
<?php } ?>
</div>

This code shows the small version of the big photos.

The problem here is that even though I upload 2 different photos, I can only take 1 photo. How can I show 2 different photos?

sql query stops searching after 412 records [duplicate]

I have built a simple login system to my custom website i have made a table on my database in phpmyadmin where i store usernames & passwords and now i realize that after 412 record the sql query cant find a match for a username and password. Iam trying to search the whole table but it stops right there.


``
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("******", "*******", "*******", "********");
// SQL query to fetch information of registered users and finds user match.
$query = "SELECT username, password from login where online=1 AND username='" . $username . "' AND password='" . $password . "' LIMIT 1";
// To protect MySQL injection for Security purpose
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->fetch()){ //fetching the contents of the row {
$_SESSION['login_user'] = $username; // Initializing Session
header("location: user_profile"); // Redirecting To Profile Page
}
``

WordPress Custom Query and filter with wpgridbuilder

I have a problem with pagination.

when I select the filters created with wpgridbuilder, even if I go from 1300+ to only 70 products, I still see all the pages (from 1 to 46), instead of only seeing 3. maybe I’m wrong in declaring:echo paginate_links( array(‘total’ => $products->max_num_pages ?

<section class="full-width">
                <div class="grid-1-3-m pad-tb">
                  <div class="facet-prod c-one">
                    <?php
                      wpgb_render_facet( [ 'id' => 1, 'grid' => 'wpgb-content' ] );
                      wpgb_render_facet( [ 'id' => 2, 'grid' => 'wpgb-content' ] );
                      wpgb_render_facet( [ 'id' => 3, 'grid' => 'wpgb-content' ] );
                    ?>
                  </div>
                  <?php
                    $queried_term = get_queried_object();  
                    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
                    $args = array(
                      'post_type' => 'product',
                      'posts_per_page' => 30,
                      'paged' => $paged,
                      'tax_query' => array(
                        array(
                          'taxonomy' => 'product_cat',
                          'field' => 'slug',
                          'terms' => $queried_term->slug
                        )
                      ),
                      'wp_grid_builder' => 'wpgb-content'
                    );
                    $products = new WP_Query( $args );
                    if( $products->have_posts() ):
                      echo '<div id="repeater" class="wpgb-content grid-5 c-three">';
                      while( $products->have_posts() ): $products->the_post();
                        $product = wc_get_product(get_the_ID());
                        $category = get_the_terms(get_the_ID(), 'product_cat')[0];
                        $price = $product->get_price();
                        $sale_price = $product->get_sale_price();
                        $title = get_the_title();
                        $titolo = $title;
                        $featured_image = get_the_post_thumbnail_url();
                        ?>
                        <div class="box-prod">
                          <a class="box-prod__link clickable-parent" target="_self" href="<?php the_permalink(); ?>" aria-label="<?php echo $titolo; ?>">
                            <h2 class="box-prod__heading"><?php echo $titolo; ?></h2>
                          </a>              
                          <a href="<?php echo get_term_link( $category ); ?>" class="box-prod__cat clickable-child"><?php echo $category->name; ?></a>
                          <img class="box-prod__featured" loading="lazy" src="<?php echo $featured_image; ?>" alt="<?php echo $titolo; ?>">
                          <p class="box-prod__price">
                            <?php 
                              if ($sale_price) {
                                echo wc_price($sale_price);
                              } else {
                                echo wc_price($price);
                              }
                              ?>
                              </p>
                                        </div>
                                    <?php
                                      endwhile;
                                      echo '</div>';
                                      echo '<div class="main-pagination c-three">';
                                      echo paginate_links( array(
                                        'total' => $products->max_num_pages
                                      ) );
                                      echo '</div>';
                                    endif;
                                    wp_reset_postdata();
                                  ?>
                                </div>
                              </section>

Woocommerce get stock function in php

I need to add echo $product->get_stock_quantity() in following code to display it in pdf. Can you please help me to insert this $product->get_stock_quantity() into code bellow:

foreach ($order->get_items() as $item_id => $item) { 

            $product = wc_get_product($item->get_product_id());

            $with_tax = $product->get_price_including_tax();

            $without_tax = $product->get_price_excluding_tax();

            $tax_amount = $with_tax - $without_tax;

            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $item->get_product_id() ),'thumbnail' );

            $css = ($item->get_quantity() > 1)?'color:red;':'';

            ?>

        

        <tr><td><?php echo $product->get_sku();?></td><td><img width='60' src="<?php echo $image[0]; ?>"/></td><td style="text-align: center;font-family:DejaVu Sans, sans-serif;font-size:12px;"><?php echo $item->get_name();?></td><td style="text-align: center;"><img width='60' src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=<?php echo $product->get_sku();?>"/></td><td style="text-align: center; <?php echo $css;?>"><?php echo  $item->get_quantity();?></td><td><?php echo wc_price( $with_tax );?> </td><td style="text-align: center;font-family:DejaVu Sans, sans-serif;">[]</td></tr>

Not succed to make myself.

ItemList.js:15 Uncaught TypeError: items.map is not a function

I am using React Js as frontend and core Php as backend. I store data through a form in Mysql and then want to display that data in the UI on another page. There is no use of Props .Below is my React js code

import React, { useState, useEffect } from "react";
import { Container, Row, Col } from "react-bootstrap";
import axios from "axios";

function ItemList() {
  const [items, setItems] = useState([]);
  useEffect(() => {
    axios.get("http://localhost/reactphp/items/").then(function (response) {
      setItems(response.data);
      // console.log(items);
    });
  }, []);
  return (
    <Container>
      <Row>
     
        {items.map((item, key) => (
          <Col lg="4" sm="6" key={key}>
            <img src={item.image} alt="pic" />
            <h3>{item.name}</h3>
            <span>{item.price}</span>
          </Col>
        ))}
      </Row>
    </Container>
  );
}

export default ItemList;

Below is my Php code.

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Origin: *");
include 'conn.php';
$getData = "SELECT * FROM items";
$result = $conn->query($getData);
$data = array();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}
echo json_encode($data);
print_r($data);
?>

I tried it almost everywhere but could not get the answer

Typo3 can’t get values from DataBase

Typo3 10.4
I created Models, Repositories and Controller. Values are getting written from the backend into the database but I can’t get a bunch of values to the frontend. It’s not all values that don’t work but some.

class Element extends TYPO3CMSExtbaseDomainObjectAbstractEntity
{
    protected $type = "";
    protected $name = "";
    protected $beschreibung = "";
    protected $customRender = "";
    protected $mehrHtml = "";
    protected $formsUsingThisElement = "";

    public function __construct(string $type='', string $name='', string $beschreibung = '', string $customRender = '') {
        $this->setType($type);
        $this->setName($name);
        $this->setBeschreibung($beschreibung);
        $this->setCustomRender($customRender);
    }

    public function setType(string $type):void {
        $this->type = $type;
    }
    public function getType():string {
        return $this->type;
    }

    public function setName(string $name):void {
        $this->name = $name;
    }
    public function getName():string {
        return $this->name;
    }

    public function setBeschreibung(string $beschreibung):void {
        $this->beschreibung = $beschreibung;
    }
    public function getBeschreibung():string {
        return $this->beschreibung;
    }

    public function setCustomRender(string $customRender):void {
        $this->customRender = $customRender;
    }
    public function getCustomRender():string {
        return $this->customRender;
    }

    public function setMehrHtml(string $mehrHtml) {
        $this->mehrHtml = $mehrHtml;
    }
    public function getMehrHtml() {
        return $this->mehrHtml;
    }

    public function setFormsUsingThisElement(string $formsUsingThisElement):void {
        $this->formsUsingThisElement = $formsUsingThisElement;
    }
    public function getFormsUsingThisElement(): string {
        return $this->formsUsingThisElement;
    }
}

Both $mehrHtml and $customRender actually have values but I can only get the other variables from the database.
While $type is of type select, $name and $beschreibung are of types input the two variables which I can not get the value of are config.type=’text’ in the TCA. But that shouldn’t matter as I got another model which holds a text which is readable but an integer which I, too, can not get the value.

enter image description here

the select where clause doesn’t read or working properly and show all existing records from specified id mysql-php

enter image description herehello I know this sound stupid but I’m practicing how to code and use relational database using core php and mysql and the select query I made is showing the all the result from database from grade 7 and 8 it should show only grade 9 because the school year status is set to yes from that particular school year and I can’t see what I did wrong I’m pretty sure I’m doing it right already

$status = 'Yes';
$adviser_id = $_SESSION['user_id']; 
$stmt = $mysqli->prepare("SELECT student_class.student_id, student_info.lrn_no, student_info.lastname, student_info.firstname, student_info.middlename, student_class.school_year,student_class.grade, student_class.section, student_class_info.action FROM student_class  
INNER JOIN student_info ON student_class.student_id = student_info.student_id  
INNER JOIN  student_class_info ON student_class.student_id = student_class_info.student_id 
INNER JOIN school_year ON student_class.school_year = school_year.sy_id 
INNER JOIN users ON student_class.adviser_id = users.user_id WHERE school_year.status=? AND student_class.adviser_id = ? ");

    //bind parameter
    $stmt->bind_param("si", $status, $adviser_id); 
    //execute  
    $stmt->execute();
    //bind variables to prepared statement +
    $stmt->bind_result( $student,$lrn, $ln, $fn, $mn,$sy,$grade, $section, $action);
    //fetch the data
    while ($stmt->fetch()){


    ?>
<tr> 

                
    <td style="display:none;" class="student_id"><?php echo $student ?></td>             
    <td><?php echo $lrn ?></td>
    <td style="text-transform:capitalize;"><?php echo $ln ?>, <?php echo $fn ?> <?php echo $mn ?></td>
    <td class="d-flex justify-content-center">
            <a href="viewstudentinfo.php?student=<?php echo $student ?>"><button class="btn btn-info info_btn" data-bs-toggle="modal" ><i class="bi bi-info-circle"></i> Info</button></a> &nbsp&nbsp&nbsp&nbsp
            <a href="form137.php?student=<?php echo $student ?>"><button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#editModal" ><i class="bi bi-eye"></i> Form 137</button></a> &nbsp&nbsp&nbsp&nbsp
            <a href="record.php?student=<?php echo $student ?>&current=<?php echo $grade?>&class=<?php echo $section?>&yearid=<?php echo $sy?>"><button class="btn btn-danger"><i class="bi bi-archive"></i> Record</button></a>
    </td>
        
        <?php if($action=='PROMOTED'){ ?>  

        <td class="text-center" style="color:green;"> <b><?php echo $action?></b></td>
        <?php } elseif ($action=='RETAINED'){ ?>
        <td class="text-center" style="color:red;"><b><?php echo $action ?><b></td>
        <?php } else {?>
        <td class="text-center"><b><?php echo $action ?><b></td>
        <?php } ?>
</tr>

<?php
      } 
      $stmt->close();
                                   

Create flat directory from zip

In my controller I receive ZIP file, which may contain xml and nested multi level zip files.
How to create flat directory, which will contain only xml files recursively extracted from all zip files?

how to use associateArray as a key in other associativeArray in PHP (just like using HashMap as key in another HashMap in JAVA)

In Java, we can use HashMap as a key in other HashMap. I’m using an associative array as a map in PHP. Now there is a need to store an associative array as a key in another associative array.
I asked ChatGPT and it presented a lengthy solution:
Suppose $map is an array that I want to use as a key:

    ksort($map);
    $key = serialize($map);

    if(!isset($main[$key])){
        $main[$key] = 0;
    }
    $main[$key]++

Yes, I need to use ksort because the next $map could contain the same array but keys could be in a different order.

I also used spl_object_hash instead of serialize but it didn’t work. please suggest an optimal approach just like hashmap in java.
Also, I used splObjectStorage class by type-casting the array into an object but it gives incorrect results.

WooCommerce reorder account passwort field on checkout

I try to reorder the WooCommerce account password field on the checkout page with the code below. However, it creates a new field but does not move the account password field.

I followed the instructions from that page here: https://jeroensormani.com/ultimate-guide-to-woocommerce-checkout-fields/#sorting-checkout-fields

How can I reorder the account password filed on WooCommerce checkout?

Goal: The Account password field should be after the email field.

function js_sort_checkout_fields( $fields ) {
    $fields['billing']['account_password']['priority'] = 111;

    return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'js_sort_checkout_fields' );``` 

PHP : Why did a multidimensionnal array disappear of $_SESSION between two pages?

I do a quiz why takes 10 questions in a database and print them with html one by one after checking if responses are trues or falses. These questions are stored in a $_SESSION[‘questions’] as a multidimensionnal array.
My problem is between two pages, the one wich print the questions and responses, and the other which check if the response is true or false. This page upgrade a $_SESSION[‘count’] by 1 to print the next question and if it’s true, the $_SESSION[‘score’] is upgraded by one.
When the program return on the quizEcho.php score and count are well upgraded, but my array in $_SESSION[‘questions’] disappear. Is someone know why ?

quizEcho.php :

<?php session_start()?>
<!DOCTYPE html>
<html lang='fr'>
<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>Quiz <?=$_SESSION['theme']?></title>
</head>
<body>


    <?php
        echo"<br> before if :";
        var_dump(isset($_SESSION['questions']));

    if (!isset($_SESSION['questions'])){
        require_once('./traitements/connexionToDB.php');

        $query = $db->prepare(" SELECT * FROM questions 
                                WHERE theme = :theme
                                ORDER BY RAND()
                                LIMIT 10");
        $query -> execute(['theme' => $_SESSION['theme']]);
        $_SESSION['questions'] = $query->fetchAll();
    }

    $questionNumberView = $_SESSION['count'] + 1;

    echo"<br> after if :";
    var_dump(isset($_SESSION['questions']));


    if ($_SESSION['count'] < 10){
        echo "
        <h2>{$_SESSION['questions'][$_SESSION['count']]['question']}</h2>
        <form action='./traitements/answerToScore.php' method='get'>
            <input type='hidden' name='answer' value='a1'>
            <input type='hidden' name='id' value='{$_SESSION['questions'][$_SESSION['count']]['id']}'>
            <input type='submit' value='{$_SESSION['questions'][$_SESSION['count']]['a1']}'>
        </form>
        <form action='./traitements/answerToScore.php' method='get'>
            <input type='hidden' name='answer' value='a2'>
            <input type='hidden' name='id' value='{$_SESSION['questions'][$_SESSION['count']]['id']}'>
            <input type='submit' value='{$_SESSION['questions'][$_SESSION['count']]['a2']}'>
        </form>
        <form action='./traitements/answerToScore.php' method='get'>
            <input type='hidden' name='answer' value='a3'>
            <input type='hidden' name='id' value='{$_SESSION['questions'][$_SESSION['count']]['id']}'>
            <input type='submit' value='{$_SESSION['questions'][$_SESSION['count']]['a3']}'>
        </form>
        <form action='./traitements/answerToScore.php' method='get'>
            <input type='hidden' name='answer' value='a4'>
            <input type='hidden' name='id' value='{$_SESSION['questions'][$_SESSION['count']]['id']}'>
            <input type='submit' value='{$_SESSION['questions'][$_SESSION['count']]['a4']}'>
        </form>
        <div id='questionNumberView'>
        Question {$questionNumberView}/10;
        </div>
        <div id='scoreView'>
        Score = {$_SESSION['score']};
        </div>
        ";
    } else {
        echo"Bravo, vous avez obtenu {$_SESSION['score']} points !";
        echo"<a href='./index.php'>Retour à l'accueil</a>";
    };
    

    ?>

    
    
</body>
</html>

answerToScore.php :

<?php
session_start();

require_once('../traitements/connexionToDB.php');
$query = $db->prepare(" SELECT * FROM questions 
                        WHERE id = :id");
$query -> execute(['id' => $_GET['id']]);
$response = $query -> fetch();

if ($response[$_GET['answer']] == $response['true_answer']){
    $_SESSION['score']+=10;
    $_SESSION['count']++;
} else {
    $_SESSION['count']++;
}

session_write_close();
header('Location: ../quizEcho.php');
exit();

After reading some forums I tried to append “session_write_close()” before the header redirection but unsuccessfull.. Is anyone see something I can’t see? Or is it impossible to store an array in a $_SESSION ? What’s the solution?

Why does my website get this error 500 http

after i click on login button i get erro 500 can’t handle request,

Then i check the error_log file, i got these two errors:

#0 /home4/wembacom/public_html/crm/includes/main/WebUI.php(174): Vtiger_WebUI->checkLogin(Object(Vtiger_Request))

#1 /home4/wembacom/public_html/crm/index.php(18): Vtiger_WebUI->process(Object(Vtiger_Request))

#2 {main}

Error screenshot

i fixed many errors before , but i can’t figure out the problem here if anyone could explain or help me

change json column to many to many relation without losing data

i am working on a project with laravel (doctrine orm)

i have a table named posts

posts table has a json column named tags,
every post’s tags stored in their json column

im trying to change it to a many to many relationship.

Problem: i need to have same tags in my new structure. and i don’t know what is the best way to do this change and store all of my json tags in my posts_tags table.

Note: my problem is not about changing the structure, its about having same data after this change.