AJAX POST Not Returning php mysql ajax

I’m trying to get data from the database using ajax to insert it in other element but the post data not passing to get-data.php
so what the reason can be and the solution
enter image description here
passed data shown here but no resposns

addBuilding.php

<?php
require_once("./dbConfig.php");
$selectIL = "SELECT * FROM  iller ";
$selectIL = $db->prepare($selectIL);
$selectIL->execute();
$res = $selectIL->get_result();
?>

<form action="" method="post">
    <select name="pp" id="cites">
        <option value="">-select state-</option>
        <?php
        while ($row = $res->fetch_assoc()) {
        ?>
            <option value="<?= $row['id'] ?>"><?= $row['il_adi'] ?></option>
        <?php
        }
        ?>
    </select>
    <select name="district" id="district">
         <option value="">-select district-</option>
    </select>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
   <script src="getdata.js"></script>

getdata.js

$(document).ready(function() { 
    $("#cites").change(function() {
        if ( $("#cites").val()!="") {
            $("#district").prop("disabled",false);
        }else  {
            $("#district").prop("disabled",true);
        }
        var city = $("#cites").val(); 
        $.ajax({ 
            type: "POST",    
            url:"get-data.php",
            data:$(city).serialize(),
            success: function(result) {
                $("#district").append(result); 
            }
        });

    });
});

get-data.php
I can see the form data in network inspection put no data passing to get-data.php

<?php
require_once("./dbConfig.php"); 

if (isset($_POST['pp'])) {
   
    $cites = $_POST['cites'];
    $selectIlce = "SELECT * FROM  ilceler where il_id=? ";
    $selectIlce = $db->prepare($selectIlce);
    $selectIlce->bind_param("i", $cites);
    $selectIlce->execute();
    $res = $selectIlce->get_result();
?>
    <?php
    while ($row = $res->fetch_assoc()) {
    ?>
        <option value="<?= $row['id'] ?>"><?= $row['ilce_adi'] ?></option>
<?php
    }
}
?>

run command line program and enter password from php

I have a command line program which requires for the user to type a password in order to run. I want to run it and enter the password through a php script.

I have tried using proc_open, using the following code, but it does not work. It reads the input, but fwrite does not seem to do anything.

$cmd = "cmd /c command_line_program";

$descriptorspec = array(
    0 => array('pipe', 'r'),  //STDIN
    1 => array('pipe', 'w'),  //STDOUT
    2 => array('pipe', 'r'),  //STDERR
);
$process = proc_open(
    $cmd,
    $descriptorspec, $pipes, null, null);
if (is_resource($process)) {
    $buffer = "";
    // Read from the command's STDOUT until it's closed.
    while (!feof($pipes[1])) {
        $input = fread($pipes[1], 8192);
        $buffer .= $input;

        if (strpos($buffer, 'Password:') !== false){
            fwrite($pipes[0], "userpassn");
        }
    }
    proc_close($process);
} else {
    echo 'Not a resource';
}

What am I doing wrong? Is there some other solution except proc_open? I am using windows and php 7.2.

Paypal Integration in PHP checkout/v2/UpdateOrder REFERENCE_ID_NOT_FOUND

I try to implement paypal express checkout in a way that users are able to manipulate their order after they logged in with Paypal and when they are done, click “bux now” and the actual payment is capured.

To do so, I created the order with paypal before with intend “Authorize”. The user logs into paypal and comes back to my shop to manage the order. When done, I want to use paypals updateOrder Call to apply the users changes. But It always bounces with error REFERENCE_ID_NOT_FOUND.

Here is the documentation:
https://developer.paypal.com/api/orders/v2/#orders_patch

Here is, what I send to Paypal.


[{
    "op": "replace",
    "path": "/purchase_units/@reference_id=='default'",
    "value": [{
        "reference_id": "2295037",
        "description": "Your order at Shop",
        "custom_id": "Shop Id 2295037",
        "soft_descriptor": "Shopname",
        "invoice_id": "2295037",
        "amount": {
            "currency_code": "EUR",
            "value": 59.98,
            "breakdown": {
                "item_total": {
                    "currency_code": "EUR",
                    "value": 50.4
                },
                "shipping": {
                    "currency_code": "EUR",
                    "value": 0
                },
                "discount": {
                    "currency_code": "EUR",
                    "value": 0
                },
                "tax_total": {
                    "currency_code": "EUR",
                    "value": 9.58
                }
            }
        },
        "items": [{
            "name": "Product 1",
            "description": "Product Descr. 1",
            "sku": "1019879",
            "unit_amount": {
                "currency_code": "EUR",
                "value": 16.8
            },
            "tax": {
                "currency_code": "EUR",
                "value": 3.19
            },
            "quantity": "1",
            "category": "PHYSICAL_GOODS"
        }, {
            "name": "Product 2",
            "description": "Product Descr. 2",
            "sku": "1024593",
            "unit_amount": {
                "currency_code": "EUR",
                "value": 33.61
            },
            "tax": {
                "currency_code": "EUR",
                "value": 6.38
            },
            "quantity": "1",
            "category": "PHYSICAL_GOODS"
        }],
        "shipping": {
            "name": {
                "full_name": "John Doe"
            },
            "address": {
                "address_line_1": "Badensche Str. 24",
                "address_line_2": "",
                "admin_area_2": "Berlin",
                "postal_code": "10715",
                "country_code": "DE"
            }
        }
    }]
}]

The answer from Paypal is “REFERENCE_ID_NOT_FOUND”. Paypal itself suggests ‘default’ if there is only one purchase unit (which it is). I also tried to replace ‘default’ with the reference_id in our system (which was provided with the createOrder call) or paypal´s own transactionId (which is provided through the endpoint anyway). The error is always the same.

How can I change this call so that Paypal accepts it and updates the order in its system?

Tui calendar javascript working on localhost but not working host

I’m building a calendar application using tui calendar.
With the changes I made in ‘app-calendar.js’ and ‘schedules.js’, I brought the calendar to the format I wanted.
It works fine on localhost. But when I upload it to the live server, the changes I made in ‘app-calendar.js’ and ‘schedules.js’ are not visible, not working as i want.

Change background color based on product type in Woocommerce admin orders list

I want to conditionally change order’s background color in Woocommerce admin orders list. There is an item called assortment and another item called multiple, if order contains one of them or both of them, the background color will change. My code does work, the probolem is when I delete any item from the store that has a purchase history, I get a fatal error which is said there is an uncaught error in my code, and I have to delete all purchases for this item to stop the fatal error, how can I resolve it? Anyone can tell me what’s wrong with my code?

My Code:

add_action( 'manage_shop_order_posts_custom_column', 'custom_orders_column', 10, 2 );
function custom_orders_column( $column, $post_id ) {
    $order = wc_get_order( $post_id );
    $items = $order->get_items();
    $order_has_assortment = false;
    $product_ids = array( 1911, 1919 );
    foreach ( $items as $item ) {
    if ( in_array( $item->get_product_id(), $product_ids ) ) {
        $order_has_assortment = true;
        break;
        }
    }
    $order_has_multiple = false;
    $term_names = array( 'Twice', '3 times', '4 times', '5 times', '6 times', '7 times', '8 times', '9 times', '10 times', '11 times', '12 times' );
    foreach ( $items as $item ) {
    $product = $item->get_product();
    if ( in_array( $product->get_attribute('pa_frequency'), $term_names ) ) {
        $order_has_multiple = true;
        break;
        }
    }
    if ( $order_has_assortment && !$order_has_multiple ) {
    ?>
    <script>
    jQuery(document).ready(function(){
        jQuery("#post-<?php echo $post_id; ?>").css("background-color", "#ffccd5");
    });
    </script>
    <?php
    }
    elseif ( !$order_has_assortment && $order_has_multiple ) {
    ?>
    <script>
    jQuery(document).ready(function(){
        jQuery("#post-<?php echo $post_id; ?>").css("background-color", "#ffff99");
    });
    </script>
    <?php
    }
    elseif ( $order_has_assortment && $order_has_multiple ) {
    ?>
    <script>
    jQuery(document).ready(function(){
        jQuery("#post-<?php echo $post_id; ?>").css("background-color", "#ccffcc");
    });
    </script>
    <?php
    }
}

How to get data from wordpress database to android-studio app without passing password and login

I would like to create app available both on web browser and android.
I would like site created using WordPress and phpMyAdmin.

For browser it’s easy for me to connect it to the database and get/set data there using php but my problem starts when I want to connect android app to the same database. I found java library that request me to put in database login details. I want to avoid that because I’m afraid of that someone could get this data. Is there a way to use XML and SQL to get data from wordpress database without passing database login and pass?

ACF/WP add form values to new repeater row

  • I work on WordPress.
  • I use ACF for all form interaction.
  • I have posts with products.

I want to create different kind of ratings in the comment (quality/price – design – functionnalities – etc…) and hold them on a repeater in order to get that kind of result :

[0]
- user : 5
- Comment : Super !
- Quality/price : 5
- design : 4
- functionnalities : 4
[1]
- user : 3
- Comment : Very bad !
- Quality/price : 2
- design : 4
- functionnalities : 1
...

How to display a form that once sent by the user will add a new row in the repeater on the post Meta?

PHPUnit prints require to terminal instead of loading the file

I’m not very familiar with PHP and struggling with the PHPUnit setup for hours. This is the situation:

  • functions.php – contains functions to be tested
<?
/**
 * test function
 */
function simple($url){
    return true
}
...
  • phpunit.xml – phpunit configuration
<phpunit bootstrap="tests/bootstrap.php">
    <testsuites>
        <testsuite name='Functions tests'>
            <directory prefix="" suffix=".test.php">./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>
  • tests/functions.test.php – contains the unit tests for the functions
<?php
use PHPUnitFrameworkTestCase;
class FunctionsTest extends TestCase {

    public function test_simple(){
        $this->assertEquals(simple(), true);
    }
    ...
}
  • tests/bootstrap.php – bootstrapping file for the unittests

The content of bootstrap.php is

<?php
require_once(__DIR__ . '/../functions.php');

I then run php vendor/bin/phpunit which has a weird output.

  1. The content of the functions.php file gets printed to the terminal
  2. All tests fail with Call to undefined function simple

When I copy the content of functions.php in front of the functions.test.php all tests pass, but this shouldn’t be the solution.

maitain filtering and pagination on moving to next page on filtering Pls help i need it

I can filter data and show pagination. But i cannot keep product filter checked after i go on next page,and also on applying filter on say for eg page5 i cannot redirect user to filtered products to page 1.

          this is how i display filter checkboxes.    

               <?php
                $query = "
                SELECT DISTINCT(area) FROM property  ORDER BY area DESC
                ";
                $statement = mysqli_query($conn,$query);
                while($row=mysqli_fetch_assoc($statement)){?>
                 <div class="options" >
                    <label><input type="checkbox" class="common_selector area" 
                    value="<?php echo $row['area']; ?>" > <?php echo $row['area']; ? 
                    > </label>
                 </div>
                <?php    
                }?>

fetchdata.php

 if(isset($_POST["area"]))
 {
  $area_filter = implode("','", $_POST["area"]);
  $query .= "
   AND area IN('".$area_filter."')
  ";
 }
 $query .= " 
 LIMIT  $this_page_first_result , $results_per_page
 ";
 $statement=mysqli_query($conn,$query);
 $total_row=mysqli_num_rows($statement);
 $output = '';
 if($total_row > 0)
 {//display output 

pagination variables and display pagination links

                     $results_per_page = 7;
                     include "connect.php";
                     
                     $sql="SELECT * FROM property";
                     $resul=mysqli_query($conn,$sql);
                     $number_of_results=mysqli_num_rows($resul);
                     $number_of_pages = ceil($number_of_results/$results_per_page);
                     if (!isset($_GET['page'])) {
                                  $page = 1;
                                } else {
                                  $page = $_GET['page'];
                                }
                     $this_page_first_result = ($page-1)*$results_per_page;
                     $get = $_GET; 
                     $current_page = isset($get['page'])?$get['page'] : 1;
                     for($i=1;$i<=$number_of_pages;$i++){
         
                     $get['page'] = $i;
                     $qs = http_build_query($get,'','&amp;');
                     if($i==$current_page) {
                     $pagLink = "<a class='active' href='rooms.php?$qs'>$i</a>";
                        }else{
                         $pagLink = "<a  class='inactive' href='rooms.php?$qs'>$i</a>";
                        }
                       echo $pagLink;echo str_repeat('&nbsp;', 2); 
                       }

and finally ajax request which i send to fetchdata.php.I dont know how much you need so i am sending whole data,i dont need updation in all filter types you can just show me logic.


   function filter_data()
   {
       $('.filter_data').html('<div id="loading" style="" ></div>');
       var action = 'fetch_data';
       var minimum_price = $('#hidden_minimum_price').val();
       var maximum_price = $('#hidden_maximum_price').val();
       var typeofproperty = get_filter('typeofproperty');
       var area = get_filter('area');
       var fortypepro = get_filter('fortypepro');
       $.ajax({
           url:"fetch_data.php",
           method:"POST",
           data:{action:action, minimum_price:minimum_price, maximum_price:maximum_price, typeofproperty:typeofproperty, area:area, fortypepro:fortypepro},
           success:function(data){
               $('.filter_data').html(data);
           }
       });
   }

   function get_filter(class_name)
   {
       var filter = [];
       $('.'+class_name+':checked').each(function(){
           filter.push($(this).val());
       });
       return filter;
   }

   $('.common_selector').click(function(){
       filter_data();
   });

   $('#price_range').slider({
       range:true,
       min:1000,
       max:65000,
       values:[1000, 65000],
       step:500,
       stop:function(event, ui)
       {
           $('#price_show').html(ui.values[0] + ' - ' + ui.values[1]);
           $('#hidden_minimum_price').val(ui.values[0]);
           $('#hidden_maximum_price').val(ui.values[1]);
           filter_data();
       }
   });```
Please help me to :
1 maintain filter data on going to next page and also keep filter checkboxes on next page,
2 redirect user to page 1 on applying filter on any page,

loadHTMLFile working on localhost, but not working on server

any ideas why this code:

$doc = new DOMDocument();
    
$doc->loadHTMLFile('https://gpwcatalyst.pl/ajaxindex.php?action=BSInstrument&start=listFull&lang=PL&format=html&download_xls=1&bsi_instrument=OKR,OKM,LZH,LZP,OSP,OPD&bsi_rodzaj=N&currencies=PLN&table_order=');
    
echo $doc->saveHTML();

works fine on localhost but not working on server and gives this errors:

Warning: PHP Startup: failed to open stream: Connection timed out in /test.php on line 14

Warning: PHP Startup: I/O warning : failed to load external entity “https://gpwcatalyst.pl/ajaxindex.php?action=BSInstrument&start=listFull&lang=PL&format=html&download_xls=1&bsi_instrument=OKR,OKM,LZH,LZP,OSP,OPD&bsi_rodzaj=N&currencies=PLN&table_order=” in /test.php on line 14

Line 14 is $doc->loadHTMLFile(‘https://…

Where should I look for a solution?

Thanks

how to proccess some tags in xml?

I’m trying to read an xml and its nodes with simplexml, I can open and display it in the browser with print_r for example, but I dont get take the nodes I need , can someone help me?
I need to get the value of the following tags, on tag Descritor I need everthing is inside it, then I´ve tag ContasCorrentes that is the main array, and inside it, I´ve many others tags on the same level, as DisponibilidadeFinanceira, DomicilioBancario, CredorFornecedor and etc…
So I´ve already gotten some values from those tags but some tags has the following format →
<gen:TipoDocumentoTESTEB1</gen:TipoDocumento>

So looks like that simplexml dont understant this part on that tag → gen: and on this way I dont get the data that I need :/

follows the LINK of the example file

the other parts of the xml I´m taking like this for tests, probably isnt the best way to do it but this is what i got ↓

$xml = simplexml_load_file("C:UsersThiagoDownloadsxml-teste.xml");

foreach ($xml->ContasCorrentes->DisponibilidadeFinanceira as $key) {
    $cont++;
    echo $key->ContaContabil . " controle = " . $cont . "</br>";    
}

$cont = 0;

foreach ($xml->ContasCorrentes->DomicilioBancario as $key) {
    $cont++;
    echo $key->CodigoAplicacao . " aplicacao cod = " . $cont . "</br>";    
}

So since then thanks for any help guys !

Laravel: orderby count on pivot while filtering parent with keyword

Good morning everybody,

I have two tables, users, questions and one pivot table users_questions. A question belongs to many users. A user has many questions.

users
-----
id | name

questions
---------
id | description

users_questions
---------------
user_id | question_id

I would like to get the top 3 users who asked the most questions for a specific keyword.

To search a keyword inside a question, I use a simple filter package. The code looks like that:

Questions::with('user')
        ->filter()
        ->paginate();

To get the 3 users who asked the most questions without filtering anything, I wrote this code:

UsersQuestions::with('user')
            ->select('mep_id')
            ->selectRaw('COUNT(*) AS count')
            ->groupBy('user_id')
            ->orderByDesc('count')
            ->limit(3)
            ->get();

But I can not figure out how to “mix” those two requests together.

Thanks in advance for your help!