How to put result of MYSQL DISTINCT QUERY in a PHP VARIABLE? [duplicate]

i’ve a problem trying to get multiple values and concatenate them inside a single php string variable.

The idea is to use a MYSQL DISTINCT STATEMENT on a single column of the table like this:

$sql = "select DISTINCT(COLUMN) from table where <multiple conditions>";
$result = mysqli_query($con, $sql);

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$suppliers = $row['COLUMN'];
}

I’m sure there are 2 records in my database I want to obtain with two distinct values: ‘PLENITUDE’ and ‘IREN’ but i dont know how to concatenate them inside the variable like this:

‘PLENITUDE-IREN’

And i’m not so expert .. it seems the query is OK but if I echo $suppliers the result is null.

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens and i am new ussin pdo for connection to database

    $query="INSERT INTO users (username,pwd,email) values(':userName',':pwd',':Email')";
    $stmt=$pdo->prepare($query);

    $stmt->bindParam(':userName',$username);
    $stmt->bindParam(':pwd',$password);
    $stmt->bindParam(':Email',$email);

    $stmt->execute();

here’s my code my parameter are same but it keeps giving me this error

i have tried changing the placeholders names but did not work

.TPL files VS code extension to be able to read and format

i have an openCart project and it has .tpl files in it and its looking white text all the way

but it looks like its php and html so i need an extension to be able to read them like a normal .php file but i cant seem to find any

i tried swig extension but it is turning everything into light blue which changed nothing

Skipping all WordPress functions if there is a cached version

I started making the following caching codes in order to create an experimental plugin that provides a solution to my own needs.

add_action('wp_loaded', 'buffer_start');
add_action('shutdown', 'buffer_end');
add_action('wp', 'cache_control');

function cache_control()
{
  if (!is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) {
    $cache = get_transient('cache');

    if(!empty($cache) || $cache != '') {
        die($cache);
    }
  }
}

function buffer_start()
{
  ob_start("callback");
}

function buffer_end()
{
  ob_get_clean();
}

function callback($html)
{
  if (!is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) {
      $cache = get_transient('cache');
      
      if(empty($cache) || $cache == '') {
          set_transient('cache', $html);
      }
  }
  return $html;
}

Leaving aside the many shortcomings in the scenario and the fact that the first cache will appear on all pages, I have a few questions.

  • ideaFirst of all, if there is HTML in the cache, WordPress functions should work as little as possible and respond to the server response as soon as possible.
  • question – In this case, are the hooks I used in my coding correct?

What I’m saying is, is there a hook that kicks in earlier to check for cache availability with the add_action('wp' hook, and if so, prevent WordPress from wasting more time? Or is that correct?

  • idea – If a cache is found, WordPress needs to respond in the most appropriate and fast way possible and skip the time it takes to produce an HTML result.
  • Question – You may have noticed that I used the PHP die() feature to do this. In practice this doesn’t make much sense to me, but I should get out of there as soon as possible and not follow WordPress’ classic functions to return a “200 Response”. Is there a more convenient way or a WordPress feature to do this? Or is the way I’m doing the best?

Of course, apart from all these, “Lite Speed Cache” etc. I know many plugins do all of this completely and intelligently. My goal is primarily to push the limits, create my own infrastructure, and of course write a special plugin that offers specific solutions to my needs. For this reason, I wanted to tinker with the plugins I mentioned to get help, but they have a very complex and difficult infrastructure to reverse engineer.

So, generally is the path I followed correct or if there are alternative and better solutions at the beginning, I want to move forward by completing them for these few important features because I know that as I start to go into details, things will start to get a little more complicated 🙂

call_user_func_array(): Argument #1 ($callback) must be a valid callback

I’m currently developing a WordPress plugin.
The main class I have created activates and deactivates all necessary functions, settings and files for the plugin and I use composer to manage the inclusion of classes.

Yesterday I changed the main psr-4 folder from src/ to admin/builder/ and this caused problems.
Now the hierarchy of the project is like this:

onfeed-facebook
|---admin
    |---builder
        |---Action
        |---RSA
        |---View
        |---OnFeedMain.php
|---vendor
|---assets
|---onfeed.php
|---...

I should point out that after editing the composer.json file I also ran the composer dump-autoload command… but I still get this error:

Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object in C:wwwclientwp.localwp-includesclass-wp-hook.php:310 
Stack trace: 
#0 C:wwwclientwp.localwp-includesclass-wp-hook.php(334): WP_Hook->apply_filters('', Array) 
#1 C:wwwclientwp.localwp-includesplugin.php(517): WP_Hook->do_action(Array) 
#2 C:wwwclientwp.localwp-adminincludesplugin.php(816): do_action('deactivate_onfe...', false) 
#3 C:wwwclientwp.localwp-adminplugins.php(209): deactivate_plugins('onfeed-facebook...', false, false) 
#4 {main} thrown in C:wwwclientwp.localwp-includesclass-wp-hook.php on line 310

Here’s the composer.json file:

    "autoload": {
        "psr-4": {
            "Oppimittinetworking\OnfeedFacebook\": "admin/builder/"
        }
    },
    "config": {
        "optimize-autoloader": true
    }

This is the OnFeedMain.php Class:

namespace OppimittinetworkingOnfeedFacebook;
use OppimittinetworkingOnfeedFacebookActionONFActivate;
use OppimittinetworkingOnfeedFacebookActionONFDeactivate;
use OppimittinetworkingOnfeedFacebookRSAONFRSAEncrypt;
use OppimittinetworkingOnfeedFacebookRSAONFRSADecrypt;

class OnFeedMain {

    public function __construct() {
        ONFActivate::activate();
        ONFActivate::register_admin_scripts();
        ONFActivate::register_wp_scripts();
    }

    public function __deactivate() {
        ONFDeactivate::deactivate();
        ONFDeactivate::unregister_admin_scripts();
        ONFDeactivate::unregister_wp_scripts();
    }

    public static function encrypt_conn() { return new ONFRSAEncrypt(); }
    public function decrypt_data() { return new ONFRSADecrypt(); }
}

Here’s the onfeed.php file:

require_once ONFEED_PLUGIN_PATH . '/vendor/autoload.php';
use OppimittinetworkingOnfeedFacebookOnFeedMain;

if ( class_exists( 'OnFeedMain' ) )
    $onfmain = new OnFeedMain();

// activaion hook
register_activation_hook( __FILE__, array( $onfmain, '__construct' ) );

// deactivation hook
register_deactivation_hook( __FILE__, array( $onfmain, '__deactivate' ) );

Here’s the functions inside ONFActivate.php and ONFDeactivate.php classes:
ONFActivate.php:

namespace OppimittinetworkingOnfeedFacebookAction;

class ONFActivate {

    public static function activate() {
        // No relevant code ...
    }

    public static function register_admin_scripts() {
        add_action( 'admin_enqueue_scripts', array( 'OppimittinetworkingOnfeedFacebookActionONFActivate', "enqueue_admin" ) );

        add_action( 'admin_menu', array( "OppimittinetworkingOnfeedFacebookActionONFActivate", 'add_admin_pages' ) );
    }

    public static function add_admin_pages() {
        add_menu_page( 'OnFeed Facebook', 'OnFeed Facebook', 'manage_options', 'onfeed_admin_menu', array( 'OppimittinetworkingOnfeedFacebookActionONFActivate', 'admin_index' ), 'dashicons-facebook-alt', 110 );
    }

    public static function admin_index() {
        require_once plugin_dir_path( __FILE__ ) . '../../admin/builder/index.php';
    }

    public static function register_wp_scripts() {
        // TODO
    }

    public static function enqueue_admin() {
        // Enqueue admin css files
        // [email protected]
        wp_register_style( "bootstrap", "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" );
        wp_enqueue_style( "bootstrap" );

        // [email protected]
        wp_register_style( "font_awesome", "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" );
        wp_enqueue_style( "font_awesome" );

        wp_enqueue_style( "onfeed_main_css", plugins_url( "../../assets/css/main.css", __FILE__ ) );
        wp_enqueue_style( "onfeed_shortcut_css", plugins_url( "../../assets/css/shortcut.css", __FILE__ ) );
        wp_enqueue_style( "onfeed_feedspage_css", plugins_url( "../../assets/css/feedspage.css", __FILE__ ) );
        
        // Enqueue admin js files
        // [email protected]
        wp_enqueue_script( "jquery_3_7_1-min", plugins_url( "../../assets/js/jquery-3.7.1.min.js", __FILE__ ), null, '3.7.1', array( 'strategy' => 'async' ) );

        wp_enqueue_script( "onfeed_function_js", plugins_url( "../../assets/js/function.js", __FILE__ ), null, '2.2.0', array( 'strategy' => 'defer' ) );
        wp_enqueue_script( "onfeed_handshake_js", plugins_url( "../../assets/js/handshake.js", __FILE__ ), null, '2.2.0', array( 'strategy' => 'defer' ) );
        wp_enqueue_script( "onfeed_shortcut_js", plugins_url( "../../assets/js/shortcut.js", __FILE__ ), null, '2.2.0', array( 'strategy' => 'defer' ) );
        wp_enqueue_script( "onfeed_feedspage_js", plugins_url( "../../assets/js/feedspage.js", __FILE__ ), null, '2.2.0', array( 'strategy' => 'defer' ) );
    }

    public static function enqueue_wp() {
        // TODO
    }
}

ONFDeactivate.php:

namespace OppimittinetworkingOnfeedFacebookAction;

class ONFDeactivate {

    public static function deactivate() {
        // Not relevant code ...
    }

    public function unregister_admin_scripts() {
        add_action( 'admin_dequeue_scripts', array( 'OppimittinetworkingOnfeedFacebookActionONFDeactivate', "dequeue_admin" ) );
    }

    public static function unregister_wp_scripts() {
        // TODO
    }

    public static function dequeue_admin() {
        // Enqueue admin css files
        wp_dequeue_style( "onfeed_main_css" );
        wp_dequeue_style( "onfeed_shortcut_css" );
        wp_dequeue_style( "onfeed_feedspage_css" );

        // Enqueue admin js files
        wp_dequeue_script( "onfeed_main_js" );
        wp_dequeue_script( "onfeed_shortcut_js" );
        wp_dequeue_script( "onfeed_feedspage_js" );
    }

    public static function dequeue_wp() {
        // TODO
    }
}

I would also let you all know thta I’ve checked if the problem was caused by the uncorrect namespace, but how you can see there’s no problem with that.

I’ve also checked this link:

but the problem still.

Thanks in advance for your reply.

how to retrieve foreign key from another table if i fetch its giving me all the primary ids instead

how to retrieve foreign key from another table if i fetch its giving me all the primary ids instead.
What am trying to achieve is when i select the primary from table A all the foreign key in table B with the same value must be select

public function getAllInvoice(){
$this->db->query(“SELECT tbl_invoice_items., tbl_invoice_total.,tbl_invoice_total.invoices_id FROM tbl_invoice_items
INNER JOIN tbl_invoice_total
ON tbl_invoice_items.invoice_fk = tbl_invoice_total.invoices_id
ORDER BY oder_date DESC”);
$results = $this->db->resultSet();
return $results;
}

Left join the same table with Doctrine

I’m going to run the following MySQL query with Doctrine (it works as expected on MySQL side):

select latest.product_id, latest.last_read_at
from attributes latest
left join attributes bigger
    on latest.product_id = bigger.product_id and
       latest.last_read_at <= bigger.last_read_at and
       latest.id < bigger.id
where bigger.last_read_at is null;

Here is my try with Doctrine:

$queryBuilder = $this->entityManager->createQueryBuilder();
        $categoryVersions = $queryBuilder
            ->select('latest.product_id', 'latest.last_read_at')
            ->from($entityClass, 'latest')
            ->leftJoin(
                $entityClass,
                'bigger',
                Join::ON,
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->eq('latest.product_id', 'bigger.product_id'),
                    $queryBuilder->expr()->lte('latest.last_read_at', 'bigger.last_read_at'),
                    $queryBuilder->expr()->lt('latest.id', 'bigger.id')
                )
            )
            ->where('bigger.last_read_at is NULL')
            ->getQuery()
            ->getResult();

Which transforms into DQL:

SELECT latest.product_id, latest.last_read_at
FROM MyNamespaceEntityAttribute latest
LEFT JOIN MyNamespaceEntityAttribute bigger ON
    latest.product_id = bigger.product_id AND  
    latest.last_read_at <= bigger.last_read_at AND
    latest.id < bigger.id
WHERE bigger.last_read_at is NULL

And here is the result:

[DoctrineORMQueryQueryException]                                      
[Syntax Error] line 0, col 156: Error: Expected end of string, got 'ON' 

Can you please help me with building the correct DQL?

max execution time reached instead of throwing error

I have an application in Laravel 10. this application hosted in Apache (not using php artisan serve). every time there is an error, the page loading untill it reach max_execution_time, and there’s nothing usefull showing on that page. this made it hard to debug what causing the error?
anybody know how to fix this? I am sorry if I posted it in wrong forum

enter image description here

The GET method is not supported for route Supported methods: POST

I just have hosted a php and laravel application in linux server. its a shared hosting . I have purchsed the code and implemented the application . The company which developed the application is telling that its your hosting is not supported for GET method .

This is the response i am getting from the server .

“message”: “The GET method is not supported for route admin/store-login. Supported methods: POST.”,
“exception”: “SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException”,
“file”:

I attached the screen short that return the error .

Godaddy customer support is telling that you havev to purchase the VIrtual private Hosting .

Please any experts advice is greately appreciated in this regards,

Thanks ,
Martin .Error Screen short for better understanding

I tried godaddy customer service and application development company.both of them are telling different stories as in my hosting another couple of php and laravel application is running very well .
So please any expert can advise me to get the problem solved

Checking domain and nameservers in PHP script not working as expected

I’m working on a form in PHP that checks if a domain is available and if the nameservers are correct. However, I’m facing issues with the validation of the domain and nameservers.

<form id="domainForm">
    Subdomain: 
    <input type="text" id="subdomainInput" name="subdomain">
    Domain: 
    <select id="domainSelect" name="domain">
        <option value="faucet.lol">faucet.lol</option>
        <option value="freecrypto.tech">freecrypto.tech</option>
        <option value="custom">Custom</option>
    </select>
    <input type="text" id="customDomainInput" class="hidden" name="customDomain">
    <button type="button" onclick="submitForm()">Submit</button>
</form>

<script>
    var domainSelect = document.getElementById('domainSelect');
    var customDomainInput = document.getElementById('customDomainInput');
    domainSelect.addEventListener('change', function() {
        if (this.value === 'custom') {
            this.classList.add('hidden');
            customDomainInput.classList.remove('hidden');
        } else {
            this.classList.remove('hidden');
            customDomainInput.classList.add('hidden');
        }
    });

    function submitForm() {
        var isCustomDomain = domainSelect.value === 'custom';
        var domain = isCustomDomain ? customDomainInput.value : domainSelect.value;
        var subdomain = document.getElementById('subdomainInput').value;
        
        fetch('checkDomain.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: 'domain=' + encodeURIComponent(domain) + '&subdomain=' + encodeURIComponent(subdomain) + (isCustomDomain ? '&customDomain=' + encodeURIComponent(customDomainInput.value) : ''),
        })
        .then(response => response.text())
        .then(data => {
            if (data === 'OK') {
                var redirectUrl = isCustomDomain ? 
                    "https://faucethost.mysellix.io/product/65096ccda9171?Domain=" + encodeURIComponent(domain) + "&Subdomain=" + encodeURIComponent(subdomain) : 
                    "https://faucethost.mysellix.io/product/65096ccda9170?Domain=" + encodeURIComponent(domain) + "&Subdomain=" + encodeURIComponent(subdomain);
                window.location.href = redirectUrl;
            } else {
                alert(data);
            }
        });
    }
</script>
<?php
function isDomainAvailable($domain)
{
    if (!filter_var($domain, FILTER_VALIDATE_URL)) {
        return false;
    }

    $curlInit = curl_init($domain);
    curl_setopt($curlInit, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($curlInit, CURLOPT_HEADER, true);
    curl_setopt($curlInit, CURLOPT_NOBODY, true);
    curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($curlInit);

    curl_close($curlInit);

    if ($response) return true;

    return false;
}

function is_valid_domain_name($domain_name) {
    return (preg_match("/^([a-zd](-*[a-zd])*)(.([a-zd](-*[a-zd])*))*$/i", $domain_name) //valid characters check
    && preg_match("/^.{1,253}$/", $domain_name) //overall length check
    && preg_match("/^[^.]{1,63}(.[^.]{1,63})*$/", $domain_name) ); //length of every label
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $subdomain = $_POST['subdomain'];
    $domain = $_POST['domain'];

    if ($domain === 'custom') {
        $domain = $_POST['customDomain'];
    }

    if (!is_valid_domain_name($domain)) {
        echo "Error: Invalid domain name.";
        return;
    }

    if (isDomainAvailable('https://' . $subdomain . '.' . $domain)) {
        echo "Error: Subdomain already exists.";
        return;
    }

    if ($domain === 'custom') {
        $dnsRecords = dns_get_record($domain, DNS_NS);

        $correctNameservers = ['ns11.webshineglobal.xyz', 'ns12.webshineglobal.xyz'];
        $hasCorrectNameservers = false;

        foreach ($dnsRecords as $record) {
            if (in_array($record['target'], $correctNameservers)) {
                $hasCorrectNameservers = true;
                break;
            }
        }

        if (!$hasCorrectNameservers) {
            echo "Error: Please set your nameservers to ns11.webshineglobal.xyz and ns12.webshineglobal.xyz.";
            return;
        }
    }

    echo "OK";
    return;
}
?>

The issue I’m facing is that when a custom domain is selected, it always redirects the user and thinks the nameservers are correct. The only case it thinks the nameservers are incorrect is if I enter the word ‘custom’ into the domain field.

I have tried adding a domain validation function and printing out the $dnsRecords array to see what dns_get_record() is returning, but I’m still not able to identify where the issue is.

I would appreciate any guidance on how to troubleshoot and correct this issue. Thanks in advance.

How to access name of taxonomy in English for English & Arabic version of website when using wpml plugin

How to access name of taxonomy in English for English & Arabic version of website when using WPML plugin

In below code i am assigning taxonomy in div so that i can assign different class to each group/team where team group could be UI designer, Senior Developer, Team Leads etc.

<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xxl-5 <?php echo preg_replace('/s+/', '_', strtolower($taxonomy->name)); ?>">

With above code it add the group/team name as ui_designer or senior_developer in English version however it add group/team name in Arabic for Arabic version which is obvious. How can i assign class name in English for Arabic version also

I am not a WP developer i am trying to change this code so that CSS works properly in Arabic version also

html page in php displaying white screen [duplicate]

I’m trying to make a profile page that shows the users username, password and email. When I go to my local host it just displays a white screen. I have a homepage that does display the HTML page in a the php file so I don’t know what I did wrong this time.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

session_start();
if ( !isset($_SESSION['loggedin']) ) {
    header('Location: index.html');
    exit;
}

$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'root';
$DATABASE_PASS = '';
$DATABASE_NAME = 'dbname';

$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
    exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}

$stmt = $con->prepare('SELECT password, email FROM users WHERE id = ?');
$stmt->bind_parem('i', $_SESSION['id']);
$stmt->execute();
$stmt->bind_result($password, $email);
$stmt->fetch();
$stmt->close();
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Profile Page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="" rel="stylesheet">
    </head>
    <body class="loggedin">
        <nav class="navtop">
            <div>
                <h1>Website Title</h1>
                <a href="profile.php"><i class="fas fa-user"></i>Profile</a>
                <a href="logout.php"><i class="fas fa-sign-out-alt"></i>Logout</a>
            </div>
        </nav>
        <div class="content">
            <h2>Profile Page</h2>
            <div>
                <p>Your account details are below:</p>
                <table>
                    <tr>
                        <td>Username:</td>
                        <td><?=$_SESSION['name']?></td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><?=$password?></td>
                    </tr>
                    <tr>
                        <td>E-mail:</td>
                        <td><?=$email?></td>
                    </tr>
                </table>
            </div>
        </div>
    </body>
</html>

I’ve looked at the error log but I didn’t find any problems and I also removed some code step by step but I can’t find what the problem is. I also couldn’t find a user who had the same problem as me.

cannot access php file via url

I’m trying to access the file index.php through url.

 http://localhost:3000/Applications/XAMPP/xamppfiles/htdocs/index.php. 

Yesterday everything was working fine but today it gives me an error saying:

“The requested resource
/Applications/XAMPP/xamppfiles/htdocs/index.php was not found on this
server.”.

The php file is in the location indicated by the url and it has not been moved.
Any help apprciated.
Thank you.

I’ve checked the folder htdocs and the file is there. I have created another php file with the same directory and the error is the same despite everything working fine yesterday.