php page print number for every page [closed]

i need to print page number for every page in print window generate




while($user_data=mysqli_fetch_assoc($user_res))
        {
        ?>
        <tr>
        <td><?= $user_data['did'] ?></td>
        <td><?= $user_data['dname'] ?></td>
        <td><?= $user_data['email'] ?></td>
        <td><?= $user_data['address'] ?></td>
        <td><?= $user_data['city'] ?></td>
        <td><?= $user_data['gender'] ?></td>
        </tr>
        

        <?php
$sn++;
        }
        ?>
      </tbody>
    </table> 
      <div class="page-number"></div>
      <div class="text-center">
        <button onclick="window.print();" class="btn btn-primary" id="print-btn">Print</button>

the output shows the page number after the table in next page enter image description here

MODX3 manager sessions expiry frequently

We have a MODX3 website with 2 editors. I don’t have any issues myself but when my friend uses Manager, he will automatically be logged out a few times in an hour and he needs to re-login. The issue occurs only when he is using a certain laptop.

I checked the logs and made an interesting remark.

My log entries are using the UTC timezone (server timezone). This is how I want it to be.
My friend’s log entries use the Finnish timezone. So the log’s timestamps look like this:

  • [2023-05-05 09:33:54] (UTC)
  • [2023-05-05 12:34:48] (Finnish time)
  • [2023-05-05 12:35:52] (Finnish time)
  • [2023-05-05 12:36:36] (Finnish time)
  • [2023-05-05 12:37:22] (Finnish time)
  • [2023-05-05 09:37:22] (UTC)
  • [2023-05-05 09:37:23] (UTC)

I was thinking that the timezone issue may affect sessions too and they, for some reason, expire.

Any ideas on how to debug the case more? How can I make sure all log entries are in the same timezone? I already set the MODX timezone setting to UTC but the issue seems to continue.

Session not displaying correctly in Laravel 10 after AJAX request

I’m developing a web application using the Laravel framework. I’m using the Laravel session system in a section of my application and have configured it to store sessions in the database.

My problem is that the session set in one of the routes of the application is not displayed correctly in other pages and instead, the value null is returned. I should mention that this problem only occurs when I send a request to the server via AJAX and update the session.

I’ve checked all the session configuration settings as well as the php.ini and .env settings, but the problem still persists. Do you have any ideas for solving this problem?

https://gist.github.com/realrezamirzaei/3fd51d57a95f90bacd3cc4aec06ba923

“I tried configuring the Laravel session to store sessions in the database, and I have checked the session settings in the php.ini and .env files. However, the session set in one of the routes of my application is not displayed correctly in other pages, and instead, the value null is returned. I was expecting the session to be displayed correctly on all pages.”

Symfony MAILER_DSN SMTP authentication error with IONOS: Expected response code “250” but got code “530”, with message “530 Authentication required

I am working on a Symfony project and trying to configure the MAILER_DSN in the .env file to send emails using the SMTP server of my email provider, IONOS.

I have set up the MAILER_DSN with the correct server name (smtp.ionos.fr), port number (465), encryption (ssl), and authentication mode (login). I have also verified that the username ([email protected]) and password (blabla@2021) are correct.

However, when I try to send an email, I get the following error:

Expected response code “250” but got code “530”, with message “530
Authentication required”.

enter image description here

Here’s my .env file :

MAILER_DSN=smtp://smtp.ionos.fr:465?encryption=tls&auth_mode=login&[email protected]&password=blabla@2021

I have already tried changing the authentication mode to cram-md5 and plain, using a different port number (587), and verifying that the SMTP server name and port number are correct. I have also checked if two-factor authentication is enabled for my email account, but it is not.

What else can I try to resolve this SMTP authentication error with Symfony and IONOS? Any suggestions or insights would be greatly appreciated.

OpenWeatherMap 7 days before weather data. Suggested api formats?

I tried using the openweathermap api for my web app just for learning but it only gives data of past 5 days and not more. I have subscribed to the student plan and if you have any format that might help me to view data of past 7 days i will be glad to be helped.

$api_url = "https://api.openweathermap.org/data/2.5/onecall/timemachine?lat={latitude}&lon={longitude}&dt={time}&appid={apikey}";

I used for loop for the days.

Weather of past 7 days

Take screenshot of conference using jitsi

i am working on jitsi meet we need to capture the screenshot of the conference and store it in Database

i tried api.captureLargeScreen but could manage to do so…
We’re looking to add a screenshot functionality to our jitsi installation. The idea is that the moderator can press a button to take a screenshot of the video conference and the screenshot will be uploaded to our server.
Is something like this possible, and if it is can someone please point us to the right direction?

Script tag doesn’t link up on new computer

I’ve recently recived a new computer, and transferred all files from the old one. Everything works fine EXCEPT one page, where the Script tag seems to be missing when I’m inspecting it in Chrome Dev-tools. It’s visible on the old computer when i inspect the page. Am i Missing something here?

Here is the page:

<?php
session_start();
if(isset($_SESSION['Loggedin']) && $_SESSION['Loggedin'] == true){
include './dbconn.php';
include './Icons.php';
$familyID = $_GET['ID'];
$sqlGetProductFamilies = "SELECT * FROM productfamily
INNER JOIN productowners ON productfamily.ProductOwnerID = productowners.ProductOwnerID
WHERE familyid= $familyID;";
$getAllProductFamilies = mysqli_query($conn,$sqlGetProductFamilies);
if(!$getAllProductFamilies){
  echo'Execution failed: '.mysqli_error($conn).'';
}else{
  while($PF = mysqli_fetch_assoc($getAllProductFamilies)){
    $familyName = $PF['familyName'];
    $ProductOwnerName = $PF['ProductOwnerName'];
  }
}
$GetInformationOnProductFamily = "SELECT 
PFSID, 
standards.StandardName, 
standards.StandardLink, 
standards.StandardType, 
productfamily.familyName, 
productowners.ProductOwnerName,
productowners.ProductOwnerID
FROM productfamilystandards
INNER JOIN productfamily ON productfamilystandards.PFSFamilyID = productfamily.familyid
INNER JOIN standards ON productfamilystandards.PFSStandardID = standards.StandardID
INNER JOIN productowners ON productfamily.ProductOwnerID = productowners.ProductOwnerID
WHERE productfamilystandards.PFSFamilyID = $familyID;";
$ResultInformationOnProductFamily = mysqli_query($conn,$GetInformationOnProductFamily);
if($ResultInformationOnProductFamily){
  while($info = mysqli_fetch_assoc($ResultInformationOnProductFamily)){
    $StandardName = $info['StandardName'];
    $StandardLink = $info['StandardLink'];
    $StandardType = $info['StandardType'];
    $FamilyName = $info['familyName'];
    $ProductOwner = $info['ProductOwnerName'];
    $ProductOwnerID = $info['ProductOwnerID'];
  }
}
?>
<!DOCTYPE html>
<html lang="en">
<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><?php echo $familyName; ?> compliance</title>
  <link rel="stylesheet" href="../CSS/style.css">
  <link rel="apple-touch-icon" sizes="180x180" href="../Images/apple-touch-icon-180x180.png">
  <link rel="icon" type="image/png" sizes="32x32" href="../Images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="../Images/favicon.ico">
  <link rel="manifest" href="/site.webmanifest">
</head>
<body>
  <div class="logo-container">
    <a href="http://localhost:81/minDB/Standards/PHP/ProductOverview.php"><img src="../Images/aura-light-international-ab-logo-vector-small.png" alt="Aura Light International AB Logo"></a>
  </div>
  <div class="productpage-image">
    <img src="<?php echo '../Images/Products/'.$familyName.'.png';?>" alt="<?php echo $familyName?>">
    <h2><?php echo $familyName ?></h2>

    <?php 
    if(empty($ProductOwnerName)){
      
      echo '<h3 id="POName">No owner assigned, please do so</h3>';
    }else{
      echo '<h3 id="POName">Product Owner: '.$ProductOwnerName.'</h3>';
    }
    ?>
    <button id="EditPO" onclick="toggleEditPO()" class="knapp hidden">Edit PO</button>
    <!-- och teamslänk kanske? -->
  </div>
    <!-- I divven under ska all information finnas på produkten -->
  <div class="windowforlists">
    <div class="listOfStandards">

      <!--Här genereras listan över alla registrerade LVD-standarder  -->

      <label for="LVD">LVD Standards</label>
      <?php if($_SESSION['Admin']== true){?>
      <div>
        <button id="editLVD" class="knapp-text">Edit</button>
        <button onclick="toggleAddNewLVD()" class="knapp-text hidden" id="addLVD">Add LVD</button>
      </div>
      <?php } ?>
      <ul name="LVD" id="LVD">
        <?php
        $GetAllLVDForFamily = "SELECT PFSStandardID, PFSID, StandardName, StandardType FROM productfamilystandards
        INNER JOIN standards ON productfamilystandards.PFSStandardID = standards.StandardID
        WHERE PFSFamilyID = $familyID AND StandardType = 'LVD';";
        $ResultofLVD = mysqli_query($conn, $GetAllLVDForFamily);
        if($ResultofLVD){
          while($LVD = mysqli_fetch_assoc($ResultofLVD)){
            $StandardName = $LVD['StandardName'];
            $StandardType = $LVD['StandardType'];
            $PFSID = $LVD['PFSID'];
            $PFSStandardID = $LVD['PFSStandardID'];
            echo '
            <li>
            <a href="./DeleteStandardOnFamily.php?PFSID='.$PFSID.'&ID='.$familyID.'">
              <img class="knapp-röd addAmendmentLVD hidden" src="'.$delete_icon.'">
            </a>';
            echo'<h3>'.$StandardName.' </h3>';
            $getallAmendmentsOnStandard = "SELECT * FROM standardamendments WHERE amendmentParentID = $PFSStandardID;";
            $resultgetallAmendmentsOnStandard = mysqli_query($conn, $getallAmendmentsOnStandard);
            if(mysqli_num_rows($resultgetallAmendmentsOnStandard) > 0){
            echo '
            <a href="./addAmendmentOnProductStandard.php?PFSStandardID='.$PFSStandardID.'&familyID='.$familyID.'">
              <img class="knapp-neutral addAmendmentLVD hidden" src="'.$Fact_icon.'">
            </a>';
            }

            //Här hämtar jag även om det finns några tillägg till standarden

            $SQLGetAmendments = "SELECT productfamilystandards.PFSAmendments, standardamendments.amendmentName FROM productfamilystandards 
            INNER JOIN standardamendments ON standardamendments.amendmentID = productfamilystandards.PFSAmendments
            WHERE PFSStandardID = $PFSStandardID AND PFSFamilyID = $familyID;";
            $GETAllAmendments = mysqli_query($conn, $SQLGetAmendments);
            if(mysqli_num_rows($GETAllAmendments)> 0){
              while($Amendments = mysqli_fetch_assoc($GETAllAmendments)){
                $amendmentName = $Amendments['PFSAmendments'];
                $amendmentsArray = explode(",", $amendmentName);
                foreach($amendmentsArray as $amendmentID){
                  $getAmendmentName ="SELECT amendmentName FROM standardamendments WHERE amendmentID = $amendmentID;";
                  $resultgetAmendmentName = mysqli_query($conn, $getAmendmentName);
                  if(!$resultgetAmendmentName){
                    mysqli_error($conn);
                    exit();
                  }else{
                    while($row = mysqli_fetch_assoc($resultgetAmendmentName)){
                      $AName = $row['amendmentName'];
                      echo '<p> + '.$AName.'</p>';
                    }
                  }
                }
              }
            }else{
              echo'</li>';
            }
          }
        }
        ?>
      </ul>

      <!--Här genereras listan över alla registrerade EMC-standarder  -->

      <label for="EMC">EMC Standards</label>
      <?php if($_SESSION['Admin'] == true){?>
      <div>
        <button id="editEMC" class="knapp-text">Edit</button>
        <button onclick="toggleAddNewEMC()" id="addEMC" class="knapp-text hidden">Add EMC</button>
      </div>
      <?php }?>
      <ul name="EMC" id="EMC">
      <?php
        $GetAllEMCForFamily = "SELECT PFSStandardID, PFSID, StandardName, StandardType FROM productfamilystandards
        INNER JOIN standards ON productfamilystandards.PFSStandardID = standards.StandardID
        WHERE PFSFamilyID = $familyID AND StandardType = 'EMC'";
        $ResultofEMC = mysqli_query($conn, $GetAllEMCForFamily);
        if($ResultofEMC){
          while($EMC = mysqli_fetch_assoc($ResultofEMC)){
            $StandardName = $EMC['StandardName'];
            $StandardType = $EMC['StandardType'];
            $PFSID = $EMC['PFSID'];
            $PFSStandardID = $EMC['PFSStandardID'];
            echo '
            <li>
            <a href="./DeleteStandardOnFamily.php?PFSID='.$PFSID.'&ID='.$familyID.'">
              <img class="knapp-röd addAmendmentEMC hidden" src="'.$delete_icon.'">
            </a>';
            echo'<h3>'.$StandardName.'</h3>';
            $getallAmendmentsOnStandard = "SELECT * FROM standardamendments WHERE amendmentParentID = $PFSStandardID;";
            $resultgetallAmendmentsOnStandard = mysqli_query($conn, $getallAmendmentsOnStandard);
            if(mysqli_num_rows($resultgetallAmendmentsOnStandard) > 0){
            echo '
            <a href="./addAmendmentOnProductStandard.php?PFSStandardID='.$PFSStandardID.'&familyID='.$familyID.'">
              <img class="knapp-neutral addAmendmentEMC hidden" src="'.$Fact_icon.'">
            </a>';
            }
            $SQLGetAmendments = "SELECT productfamilystandards.PFSAmendments, standardamendments.amendmentName FROM productfamilystandards 
            INNER JOIN standardamendments ON standardamendments.amendmentID = productfamilystandards.PFSAmendments
            WHERE PFSStandardID = $PFSStandardID AND PFSFamilyID = $familyID;";
            $GETAllAmendments = mysqli_query($conn, $SQLGetAmendments);
            if(mysqli_num_rows($GETAllAmendments)> 0){
              while($Amendments = mysqli_fetch_assoc($GETAllAmendments)){
                $amendmentName = $Amendments['PFSAmendments'];
                $amendmentsArray = explode(",", $amendmentName);
                foreach($amendmentsArray as $amendmentID){
                  $getAmendmentName ="SELECT amendmentName FROM standardamendments WHERE amendmentID = $amendmentID;";
                  $resultgetAmendmentName = mysqli_query($conn, $getAmendmentName);
                  if(!$resultgetAmendmentName){
                    mysqli_error($conn);
                    exit();
                  }else{
                    while($row = mysqli_fetch_assoc($resultgetAmendmentName)){
                      $AName = $row['amendmentName'];
                      echo '<p> + '.$AName.'</p>';
                    }
                  }
                }
              }
            }else{
              echo'</li>';
            }  
          }
        }
        ?>
      </ul>
    </div>

    <!-- Här är allt för mitten delen (Certificate/Report) -->

    <div class="listInWindow">
      <div>
        <?php
        if($_SESSION['CanSignCE'] == true){
        ?>
          <a href="./generateCE.php?familyID=<?php echo $familyID ?>"><button class="knapp-text">Generate CE</button></a><br>
        <?php } ?>

        <?php 
        if($_SESSION['Admin'] == true){
        ?>
          <button id="btnNewDoc" class="knapp-text">Add Certificate/Report</button><br>
        <?php } ?>
        <?php 
        $filequery ="SELECT * FROM files WHERE fileCEFamilyID = $familyID";
        $fileResult = mysqli_query($conn, $filequery);
        if($fileResult && mysqli_num_rows($fileResult) > 0){?>
            <form action="" method="GET">
            <table class="tabell-CE">
              <thead>
                <tr>
                  <th>Filename</th>
                  <th>Operations</th> 
                </tr>
              </thead>
              <tbody>
              <?php
                while($row = mysqli_fetch_assoc($fileResult)){ 
                  $name = $row['fileName'];
                  $fileID = $row['fileID'];
                  echo '
                  <tr>
                    <td><legend>'.$name.'</legend></td>
                    <td>
                      <a title="Download document" href="../files/Compliance/'.$name.'"><img class="knapp" src="'.$download_icon.'"></a>';
                      if($_SESSION['Admin'] == true){
                        echo'<a title="Delete document from component" href="./deletedoc.php?fileID='.$fileID.'&ID='.$familyID.'"><img class="knapp-röd" src="'.$delete_icon.'"></a>';
                      }echo '
                    </td>
                  </tr>';
                }
              }else{
                echo'
                <tr>
                  <td>No documents attached to the family of '.$familyName.'</td>
                  <td></td>
                </tr>';
              }
            ?>
            </tbody>
          </table>
        </form>

        <!-- Här är fönstret för att lägga till ny rapport eller certifikat -->

        <div id="addNewDocumentationOnFamily" class="fönster-look popup hidden">
          <form action="" method="post" enctype="multipart/form-data">
            <div class="">
              <legend>Select file to Upload</legend>
              <input type="file" name="file1"><br>
              <input hidden type="number" name="family" value="<?php echo $familyID ?>">
              <div>
                <button type="submit" name="uploadCompliance" style="background:transparent;border:none;"><img class="knapp" src="../Images/Icons/file_upload_FILL0_wght100_GRAD0_opsz40.png"></button>
              </div>
              <h5>Ladda upp en fil i formaten .zip, .pdf eller .png</h5>
              <h5>Filen får inte vara större än 10 Mb</h5>
            </div>
          </form>
          <?php
          if(isset($_POST['uploadCompliance'])){
            $filename = $_FILES['file1']['name'];
            $destination = "../files/Compliance/$filename";
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            $file = $_FILES['file1']['tmp_name'];
            $size = $_FILES['file1']['size'];
            $family = $_POST['family'];
            if(!in_array($extension, ['zip', 'pdf', 'png', 'xls', 'jpeg', 'jpg'])){
              echo "Du kan bara ladda upp .ZIP, .PDF, .PNG eller .XLS-filer till databasen";
            }elseif($size > 10000000){
              echo "Filen är för stor, den kan vara max 10 Mb.";
            }else{
              if(move_uploaded_file($file, $destination)){
                $sql = "INSERT INTO files(fileName, fileCEFamilyID) VALUES ('$filename', '$family');";
                if(mysqli_query($conn, $sql)){
                  //echo "Det gick ju galant";
                  echo"<script> window.location.href = './Productpage.php?ID=$family';</script>";
                  //header('location: ./uploads.php?compID='.$_GET['compID'].'&mainID='.$mainID.'');
                  exit; 
                } else{
                  echo "Det sket sig $conn->error";
                }
              }
            }
          }
          ?>
        </div>
      </div>
    </div>

    <!-- Här är allt för övrig data, högra fältet (Documents) -->

    <div class="listInWindow">
      <div>
      <?php 
        if($_SESSION['Admin'] == true){?>
          <button id="btnNewData" class="knapp-text">Add new document</button><br>
          <?php 
          }
          ?>
            <?php 
              $filequery ="SELECT * FROM files WHERE fileDataFamilyID = $familyID";
              $fileResult = mysqli_query($conn, $filequery);
              if($fileResult && mysqli_num_rows($fileResult) > 0){?>
              <form method="GET">
              <table class="tabell-CE">
                <tr>
                  <th>Filnamn</th>
                  <th>Ladda ner</th>
                </tr>
                <?php            
                while($row = mysqli_fetch_assoc($fileResult)){ 
                  $name = $row['fileName'];
                  $fileID = $row['fileID'];
                  echo '
                  <tr>
                    <td><legend>'.$name.'</legend></td>
                    <td>
                      <a title="Download document" href="../files/Datasheets/'.$name.'"><img class="knapp" src="'.$download_icon.'"></a>';
                      if($_SESSION['Admin'] == true){
                        echo'<a title="Delete document from component" href="./deletedoc.php?fileID='.$fileID.'&ID='.$familyID.'"><img class="knapp-röd" src="'.$delete_icon.'"></a>';
                      }echo '
                    </td>
                  </tr>';
                }
              }else{
                echo'No documents attached to the family of '.$familyName.'';
              }
            ?>
          </table>
        </form>

        <!-- Här är fönstret för att lägga till övrig dokumentation -->

        <div id="addNewDataOnFamily" class="fönster-look popup hidden">
          <form action="" method="post" enctype="multipart/form-data">
            <div class="">
              <legend>Select file to Upload</legend>
              <input type="file" name="file1"><br>
              <input hidden type="number" name="family" value="<?php echo $familyID ?>">
              <div>
                <button type="submit" name="uploadData" style="background:transparent;border:none;"><img class="knapp" src="../Images/Icons/file_upload_FILL0_wght100_GRAD0_opsz40.png"></button>
              </div>
              <h5>Ladda upp en fil i formaten .zip, .pdf eller .png</h5>
              <h5>Filen får inte vara större än 10 Mb</h5>
            </div>
          </form>
          <?php
          if(isset($_POST['uploadData'])){
            $filename = $_FILES['file1']['name'];
            $destination = "../files/Datasheets/$filename";
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            $file = $_FILES['file1']['tmp_name'];
            $size = $_FILES['file1']['size'];
            $family = $_POST['family'];
            if(!in_array($extension, ['zip', 'pdf', 'png', 'xls', 'jpeg', 'jpg'])){
              echo "Du kan bara ladda upp .ZIP, .PDF, .PNG eller .XLS-filer till databasen";
            }elseif($size > 10000000){
              echo "Filen är för stor, den kan vara max 10 Mb.";
            }else{
              if(move_uploaded_file($file, $destination)){
                $sql = "INSERT INTO files('fileName', 'fileDataFamilyID') VALUES ('$filename', '$family');";
                if(mysqli_query($conn, $sql)){
                  //echo "Det gick ju galant";
                  echo"<script> window.location.href = './Productpage.php?ID=$family';</script>";
                  //header('location: ./uploads.php?compID='.$_GET['compID'].'&mainID='.$mainID.'');
                  exit; 
                } else{
                  echo "Det sket sig $conn->error";
                }
              }
            }
          }
          ?>
      </div>
    </div>
  </div>

  <!-- Här är fönstret för att lägga till ny LVD-standard -->

  <div id="addNewLVD" class="fönster-look popup hidden">
    <button onclick="toggleAddNewLVD()" class="knapp-röd">X</button>
    <form action="" method="post">
      <select name="addLVD" id="">
      <?php 
      $GetAllLVDStandards = 'SELECT * FROM standards WHERE StandardType LIKE "LVD%";';
      $resultOfGetAllLVDStandards = mysqli_query($conn, $GetAllLVDStandards);
      if($resultOfGetAllLVDStandards){
        while($std = mysqli_fetch_assoc($resultOfGetAllLVDStandards)){
          $StandardName = $std['StandardName'];
          $StandardID = $std['StandardID'];
          $StandardDateOfEffect = $std['StandardDateOfEffect'];
          $StandardDateOfWithdrawal = $std['StandardDateOfWithdrawal'];
          $StandardDesc = $std['StandardDescription'];
          echo'
          <option value="'.$StandardID.'">'.$StandardName.'</option>';
        }
      }
      ?>  
      </select><br>
      <button type="submit" class="knapp-text" name="addLVDStd">Add to <?php echo $familyName ?></button>
    </form>
    <?php 
    if(isset($_POST['addLVDStd'])){
      $selectedStd = $_POST['addLVD'];
      $addLVDToFamily = "INSERT INTO productfamilystandards (PFSFamilyID, PFSStandardID) VALUES ('$familyID', '$selectedStd');";
      if(mysqli_query($conn, $addLVDToFamily)){
        echo "<script>alert('Standard is now added to ".$familyName."'); window.location.href='./productpage.php?ID=".$familyID."';</script>";
        }else{
          echo "<script>alert(Execution failed: ".mysqli_error($conn).")</script>";
        }
      }
    ?>
  </div>

  <!--Här är fönstret som lägger till ny EMC-standard  -->

  <div id="addNewEMC"class="fönster-look popup hidden">
    <button onclick="toggleAddNewEMC()" class="knapp-röd">X</button>
    <form action="" method="post">
      <select name="addEMC" id="">
      <?php 
      $GetAllEMCStandards = 'SELECT * FROM standards WHERE StandardType LIKE "EMC%";';
      $resultOfGetAllEMCStandards = mysqli_query($conn, $GetAllEMCStandards);
      if($resultOfGetAllEMCStandards){
        while($std = mysqli_fetch_assoc($resultOfGetAllEMCStandards)){
          $StandardName = $std['StandardName'];
          $StandardID = $std['StandardID'];
          $StandardDateOfEffect = $std['StandardDateOplaceholderfEffect'];
          $StandardDateOfWithdrawal = $std['StandardDateOfWithdrawal'];
          $StandardDesc = $std['StandardDescription'];
          echo'
          <option value="'.$StandardID.'">'.$StandardName.'</option>';
        }
      }
      ?>  
      </select>
      <button type="submit" name="addEMCStd">Add to <?php echo $familyName ?></button>
    </form>
    <?php 
    if(isset($_POST['addEMCStd'])){
      $selectedStd = $_POST['addEMC'];
      $addEMCToFamily = "INSERT INTO productfamilystandards (PFSFamilyID, PFSStandardID) VALUES ('$familyID', '$selectedStd');";
      if(mysqli_query($conn, $addEMCToFamily)){
        echo "<script>alert('Standard is now added to ".$familyName."'); window.location.href='./productpage.php?ID=".$familyID."';</script>";
        }else{
          echo "<script>alert(Execution failed: ".mysqli_error($conn).")</script>";
        }
      }
    ?>
  </div>

      <!-- Här är fönstret som lägger till Produkt ägare -->

  <div id="AddPO" class="fönster-look popup-flex hidden">
    <form method="POST">
      <select name="PO">
      <?php
      $getallPO = "SELECT * FROM productowners;";
      $resultgetallPO = mysqli_query($conn, $getallPO);
      if($resultgetallPO){
        while($PO = mysqli_fetch_assoc($resultgetallPO)){
          $ProductOwnerNameSelect = $PO['ProductOwnerName'];
          $ProductOwnerIDSelect =$PO['ProductOwnerID'];
          $ProductOwnerEmailSelect =$PO['ProductOwnerEmail'];
          echo '<option value='.$ProductOwnerIDSelect.'>'.$ProductOwnerNameSelect.'</option>';
        }
      }
      ?>
      </select>
      <button type="submit" name="submitPO" class="knapp">Update</button>
    </form>
    <?php
    if(isset($_POST['submitPO'])){
      $ProductOwnerIDUpdate = $_POST['PO'];
      $sendupdate = "UPDATE productfamily SET ProductOwnerID = $ProductOwnerIDUpdate WHERE familyid = $familyID;";
      $resultofupdatePO = mysqli_query($conn, $sendupdate);
      if($resultofupdatePO){
        echo '<script>alert("Product owner has now been updated");window.location.href="./Productpage.php?ID='.$familyID.'";</script>';
      }
      mysqli_error($conn);
    } 
    ?>
  </div>
  
    <!-- Här lägger adderar man tillägg på standarder -->

  <div id="AddAmendment" class="fönster-look popup-flex hidden">
    <form method="POST">
      <?php 
      $SQLGetAmendments = "SELECT * FROM standardamendments WHERE amendmentParentID = ;";
      $GETAllAmendments = mysqli_query($conn, $SQLGetAmendments);
      if(mysqli_num_rows($GETAllAmendments)> 0){
        while($Amendments = mysqli_fetch_assoc($GETAllAmendments)){
          $amendmentName = $Amendments['amendmentName'];
          $amendmentID = $Amendments['amendmentID'];
          echo'<input type="checkbox" name="amendment[] "value="'.$amendmentID.'">'.$amendmentName.'</input><br>';
        }
      }
      ?>
      <button type="submit" name="addAmendment" class="knapp">Update</button>
    </form>
    <?php
    if(isset($_POST['addAmendment'])){
      if(!empty($_POST['amendment'])){
        foreach($_POST['amendment'] as $amendment)
        echo $amendment;
      }
    }
    ?>
  </div>
  <script src="../JavaScript/script.js"></script>
  <?php
  }else{
    header('Location: http://localhost:81/minDB/Startpage/PHP/login.php');
    exit();
  }?>
</body>
</html>

Here is the script.file:

function toggleAddFamily(){
  document.querySelector("#mainwindow").classList.toggle("blur");
  document.querySelector("#addFamily").classList.toggle("hidden");
}
function toggleAddNewStandard(){
  document.querySelector("#addNewStandard").classList.toggle("hidden");
  document.querySelector("#mainwindow").classList.toggle("blur");
}
function toggleAddNewAmendment(){
  document.querySelector("#addNewAmendment").classList.toggle("hidden");
  document.querySelector("#mainwindow").classList.toggle("blur");
}
function toggleAddNewLVD(){
  document.querySelector("#addNewLVD").classList.toggle("hidden")
}
function toggleAddNewEMC(){
  document.querySelector("#addNewEMC").classList.toggle("hidden")
}
document.querySelector("#editEMC").addEventListener("click",() => {
  document.querySelector("#addEMC").classList.toggle("hidden");
  if(document.querySelector("#addEMC").classList.contains("hidden")){
    document.querySelector("#editEMC").innerText = "Edit";
  }else{
    document.querySelector("#editEMC").innerText = "Close edit";
  }
  document.querySelectorAll("li").forEach(function(el){
    el.querySelectorAll(".addAmendmentEMC").forEach(function(btn) {
      btn.classList.toggle("hidden");
    })
  })
})
document.querySelector("#editLVD").addEventListener("click",() => {
  document.querySelector("#addLVD").classList.toggle("hidden");
  if(document.querySelector("#addLVD").classList.contains("hidden")){
    document.querySelector("#editLVD").innerText = "Edit";
    document.querySelector("#editLVD").style.scale = "1";
  }else{
    document.querySelector("#editLVD").innerText = "Close edit";
  }
  document.querySelectorAll("li").forEach(function(el){
    el.querySelectorAll(".addAmendmentLVD").forEach(function(btn) {
      btn.classList.toggle("hidden");
    })
    // el.querySelectorAll(".addAmendmentLVD").forEach(function(btn) {
    //   btn.classList.toggle("hidden");
    // })
  })
})
function toggleEditPO(){
  document.querySelector("#AddPO").classList.toggle("hidden")
}
document.querySelector("#POName").addEventListener("click", function(){
  document.querySelector("#EditPO").classList.toggle("hidden")
})
document.querySelector('#btnNewDoc').addEventListener("click", function(){
  document.querySelector("#addNewDocumentationOnFamily").classList.toggle("hidden")
})
document.querySelector('#btnNewData').addEventListener('click', function(){
  document.querySelector('#addNewDataOnFamily').classList.toggle('hidden');
})
function toggleAddAmendment(){
  document.querySelector("#AddAmendment").classList.toggle("hidden")
}


Note that everything works perfect on my old computer.

PLEASE HELP! I’m going crazy.

I’ve placed the script at the bottom of the page, where it doesn’t render.
I’ve placed it at the head-tag, where it DOES get rendered, but pointless since the targets of the DOM is below the tag.
I’ve made hard copys from the old computer and replaced the file in the new computer with the file from the old.

How to limit google maps autcomplete search to only european countries in php?

I am trying to get autocomplete list based on input with google maps api in php. I want to get only results from Europe. I tried using ‘components’ => ‘country:de’ filter but that gets only one to five countries and I need more. Any help is appreciated. Here is my code.

php class

<?php

namespace AppSupport;

use GuzzleHttpClient;
use IlluminateSupportFacadesDB;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationResponse;

class AutocompleteHandler
{
    public const BASE_URL = "https://maps.googleapis.com/maps/api/place";
    private $key;

    public function __construct()
    {
        $this->key = config('services.googlekey.key');
    }

    public function placeId(string $address): JsonResponse
    {
        $url = sprintf(
        '%s/autocomplete/json?%s',
         self::BASE_URL,
         http_build_query([
        'input' => $address,
         'types' => '(cities)',
         'components' => 'country:de',
         'key' => $this->key,
         ]));

        try {
            $client = new Client();
            $response = $client->request('get', $url);
            $responseJson = $response->getBody()->getContents();
            $responseArray = json_decode($responseJson, true);

            return response()->json(collect($responseArray['predictions'])->map(
                function ($value) {
                    return [
                        'id' => $value['place_id'],
                        'label' => $value['description'],
                    ];
                }
            ));
        } catch (Exception $e) {
            return response()->json([
                'error' => $e->getMessage(),
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
        }
    }
}

PHP Ajax jQuery MySQL Datatables Live Editable Table – Form Submission Doesn’t Update Existing Table Data – DOES Add/Delete Table Data

Fairly new to PHP/Ajax/jQuery/MySQL and I’m stuck on this piece of a large project using a PHP Ajax jQuery MySQL Datatables Live Editable Table.

Correct data is being displayed from the server and I’m able to Add new records & Delete existing records, but nothing happens after Form Submission when attempting to Update an existing record. No errors. Have attempted debugging for several hours and I’m stuck.

Help, tips, pointers, and recommendations appreciated.

4 Primary Files Included:

  • index.php (Form for adds/updates)
  • ajax.js (scripts)
  • ajax_action.php (script/query handling)
  • Records.php (queries)

Screenshot_01

index.php:

<?php 
include('inc/header.php');
?>
<title>Found Gaming Portal</title>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>      
<link rel="stylesheet" href="css/dataTables.bootstrap.min.css" />
<script src="js/ajax.js"></script>  
<?php include('inc/container.php');?>
<div class="container contact"> 
    <h2>Vendor Management</h2>  
    <div class="col-lg-10 col-md-10 col-sm-9 col-xs-12">        
        <div class="panel-heading">
            <div class="row">
                <div class="col-md-10">
                    <h3 class="panel-title"></h3>
                </div>
                <div class="col-md-2" align="right">
                    <button type="button" name="add" id="addRecord" class="btn btn-success">Add New Vendor</button>
                </div>
            </div>
        </div>
        <table id="recordListing" class="table table-bordered table-striped table-compact">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Name</th>                   
                    <th>Type</th>
                    <th>ID #</th>
                    <th>ID Type</th>
                    <th>ID State</th>                       
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Address</th>
                    <th>Address</th>                    
                    <th>City</th>                   
                    <th>State</th>                  
                    <th>Zip</th>                    
                    <th></th>                   
                    <th></th>                   
                </tr>
            </thead>
        </table>
    </div>
    <div id="recordModal" class="modal fade">
        <div class="modal-dialog">
            <form method="post" id="recordForm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title"><i class="fa fa-plus"></i> Edit Vendor</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="Name" class="control-label">Name</label>                            
                            <input type="text" class="form-control" id="Name" name="Name" placeholder="Name" required>                          
                        </div>      
                        <div class="form-group">
                            <label for="Type" class="control-label">Vendor Type</label>
                                <select name="Type" id="Type">
                                    <option value="Individual">Individual</option>
                                    <option value="Company">Company</option>
                                </select>
                        </div>                      
                        <div class="form-group">
                            <label for="IDNumber" class="control-label">ID Number</label>                           
                            <input type="text" class="form-control"  id="IDNumber" name="IDNumber" placeholder="IDNumber">                          
                        </div>   
                        <div class="form-group">
                            <label for="IDType" class="control-label">ID Type</label>                           
                                <select name="IDType" id="IDType">
                                        <option value=""></option>
                                    <optgroup label ="State ID">
                                        <option value="DL">Drivers License</option>
                                        <option value="Non-Drive">Non-Driver License</option>
                                        <option value="Military">Military</option>
                                        <option value="Concealed Carry">Concealed Carry</option>
                                    </optgroup>
                                    <optgroup label="International ID">
                                        <option value="Passport">Passport</option>
                                        <option value="Visa">Non-Resident Visa</option>
                                    </optgroup>
                                </select>
                        </div>   
                        <div class="form-group">
                            <label for="IDState" class="IDState">ID Issuer</label>                          
                                <select name="IDState" id="IDState">
                                    <option value=""></option>                  
                                            <option value="TX">Texas</option>
                                        <optgroup label="US States/Terr">
                                            <option value="AL">Alabama</option>
                                            <option value="AK">Alaska</option>
                                            <option value="AZ">Arizona</option>
                                            <option value="AR">Arkansas</option>
                                            <option value="CA">California</option>
                                            <option value="CO">Colorado</option>
                                            <option value="CT">Connecticut</option>
                                            <option value="DC">District of Columbia</option>
                                            <option value="DE">Delaware</option>
                                            <option value="FL">Florida</option>
                                            <option value="GA">Georgia</option>
                                            <option value="GU">Guam</option>
                                            <option value="HI">Hawaii</option>
                                            <option value="ID">Idaho</option>
                                            <option value="IL">Illinois</option>
                                            <option value="IN">Indiana</option>
                                            <option value="IA">Iowa</option>
                                            <option value="KS">Kansas</option>
                                            <option value="KY">Kentucky</option>
                                            <option value="LA">Louisiana</option>
                                            <option value="ME">Maine</option>
                                            <option value="MD">Maryland</option>
                                            <option value="MA">Massachusetts</option>
                                            <option value="MI">Michigan</option>
                                            <option value="MN">Minnesota</option>
                                            <option value="MS">Mississippi</option>
                                            <option value="MO">Missouri</option>
                                            <option value="MT">Montana</option>
                                            <option value="NE">Nebraska</option>
                                            <option value="NV">Nevada</option>
                                            <option value="NH">New Hampshire</option>
                                            <option value="NJ">New Jersey</option>
                                            <option value="NM">New Mexico</option>
                                            <option value="NY">New York</option>
                                            <option value="NC">North Carolina</option>
                                            <option value="ND">North Dakota</option>
                                            <option value="OH">Ohio</option>
                                            <option value="OK">Oklahoma</option>
                                            <option value="OR">Oregon</option>
                                            <option value="PA">Pennsylvania</option>
                                            <option value="PR">Puerto Rico</option>
                                            <option value="RI">Rhode Island</option>
                                            <option value="SC">South Carolina</option>
                                            <option value="SD">South Dakota</option>
                                            <option value="TN">Tennessee</option>
                                            <option value="UT">Utah</option>
                                            <option value="VT">Vermont</option>
                                            <option value="VA">Virginia</option>
                                            <option value="WA">Washington</option>
                                            <option value="WV">West Virginia</option>
                                            <option value="WI">Wisconsin</option>
                                            <option value="WY">Wyoming</option>
                                        </optgroup>
                                    </select>
                        </div>
                        <div class="form-group">
                            <label for="Phone" class="control-label">Phone Number</label>                           
                            <input type="tel" class="form-control" id="Phone" name="Phone" placeholder="Phone" pattern="[0-9]{3}.[0-9]{3}.[0-9]{4}" maxlength="12" required>
                                <small>Format: 123.123.1234</small>
                        </div>                      
                        <div class="form-group">
                            <label for="Email" class="control-label">Email</label>                          
                            <input type="email" class="form-control" id="Email" name="Email">
                        </div>
                        <div class="form-group">
                            <label for="Address1" class="control-label">Address</label>                         
                            <input type="Address1" class="form-control" id="Address1" name="Address1">
                        </div>
                        <div class="form-group">
                            <input type="Address2" class="form-control" id="Address2" name="Address2">
                        </div>
                        <div class="form-group">
                            <label for="City" class="control-label">City</label>                            
                            <input type="City" class="form-control" id="City" name="City">
                        </div>
                        <div class="form-group">
                            <label for="State" class="control-label">State</label>                          
                                <select name="State" id="State">
                                            <option value="TX">Texas</option>
                                            <option value="AL">Alabama</option>
                                            <option value="AK">Alaska</option>
                                            <option value="AZ">Arizona</option>
                                            <option value="AR">Arkansas</option>
                                            <option value="CA">California</option>
                                            <option value="CO">Colorado</option>
                                            <option value="CT">Connecticut</option>
                                            <option value="DC">District of Columbia</option>
                                            <option value="DE">Delaware</option>
                                            <option value="FL">Florida</option>
                                            <option value="GA">Georgia</option>
                                            <option value="HI">Hawaii</option>
                                            <option value="ID">Idaho</option>
                                            <option value="IL">Illinois</option>
                                            <option value="IN">Indiana</option>
                                            <option value="IA">Iowa</option>
                                            <option value="KS">Kansas</option>
                                            <option value="KY">Kentucky</option>
                                            <option value="LA">Louisiana</option>
                                            <option value="ME">Maine</option>
                                            <option value="MD">Maryland</option>
                                            <option value="MA">Massachusetts</option>
                                            <option value="MI">Michigan</option>
                                            <option value="MN">Minnesota</option>
                                            <option value="MS">Mississippi</option>
                                            <option value="MO">Missouri</option>
                                            <option value="MT">Montana</option>
                                            <option value="NE">Nebraska</option>
                                            <option value="NV">Nevada</option>
                                            <option value="NH">New Hampshire</option>
                                            <option value="NJ">New Jersey</option>
                                            <option value="NM">New Mexico</option>
                                            <option value="NY">New York</option>
                                            <option value="NC">North Carolina</option>
                                            <option value="ND">North Dakota</option>
                                            <option value="OH">Ohio</option>
                                            <option value="OK">Oklahoma</option>
                                            <option value="OR">Oregon</option>
                                            <option value="PA">Pennsylvania</option>
                                            <option value="PR">Puerto Rico</option>
                                            <option value="RI">Rhode Island</option>
                                            <option value="SC">South Carolina</option>
                                            <option value="SD">South Dakota</option>
                                            <option value="TN">Tennessee</option>
                                            <option value="UT">Utah</option>
                                            <option value="VT">Vermont</option>
                                            <option value="VA">Virginia</option>
                                            <option value="WA">Washington</option>
                                            <option value="WV">West Virginia</option>
                                            <option value="WI">Wisconsin</option>
                                            <option value="WY">Wyoming</option>
                                </select>
                        </div>
                        <div class="form-group">
                            <label for="Zip" class="control-label">Zip</label>                          
                            <input type="Zip" class="Zip" id="Zip" name="Zip">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="id" id="id" />
                        <input type="hidden" name="action" id="action" value="" />
                        <input type="submit" name="save" id="save" class="btn btn-info" value="Save" />
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>  
<?php include('inc/footer.php');?>

ajax.js:

$(document).ready(function(){   
    
    var dataRecords = $('#recordListing').DataTable({
        "lengthChange": false,
        "processing":true,
        "serverSide":true,
        'processing': true,
        'serverSide': true,
        'serverMethod': 'post',     
        "order":[],
        "ajax":{
            url:"ajax_action.php",
            type:"POST",
            data:{action:'listRecords'},
            dataType:"json"
        },
        "columnDefs":[
            {
                "targets":[13, 14],
                "orderable":false,
            },
        ],
        "pageLength": 10
    }); 
    
    $('#addRecord').click(function(){
        $('#recordModal').modal('show');
        $('#recordForm')[0].reset();
        $('.modal-title').html("<i class='fa fa-plus'></i> Add Vendor");
        $('#action').val('addRecord');
        $('#save').val('Add');
    });     
    $("#recordListing").on('click', '.update', function(){
        var VendorID = $(this).attr("VendorID");
        var action = 'getRecord';
        $.ajax({
            url:'ajax_action.php',
            method:"POST",
            data:{VendorID:VendorID, action:action},
            dataType:"json",
            success:function(data){
                $('#recordModal').modal('show');
                $('#VendorID').val(data.VendorID);
                $('#Name').val(data.Name);
                $('#Type').val(data.Type);
                $('#IDNumber').val(data.IDNumber);
                $('#IDType').val(data.IDType);
                $('#IDState').val(data.IDState);                
                $('#Phone').val(data.Phone);
                $('#Email').val(data.Email);    
                $('#Address1').val(data.Address1);  
                $('#Address2').val(data.Address2);  
                $('#City').val(data.City);  
                $('#State').val(data.State);    
                $('#Zip').val(data.Zip);    
                $('.modal-title').html("<i class='fa fa-plus'></i> Edit Vendor");
                $('#action').val('updateRecord');
                $('#save').val('Save');
            }
        
        })
    });
    $("#recordModal").on('submit','#recordForm', function(event){
        event.preventDefault();
        $('#save').attr('disabled','disabled');
        var formData = $(this).serialize();
        $.ajax({
            url:"ajax_action.php",
            method:"POST",
            data:formData,
            success:function(data){             
                $('#recordForm')[0].reset();
                $('#recordModal').modal('hide');                
                $('#save').attr('disabled', false);
                dataRecords.ajax.reload();
            }
        })
    });     
    $("#recordListing").on('click', '.delete', function(){
        var VendorID = $(this).attr("VendorID");        
        var action = "deleteRecord";
        if(confirm("Are you sure you want to delete this vendor?")) {
            $.ajax({
                url:"ajax_action.php",
                method:"POST",
                data:{VendorID:VendorID, action:action},
                success:function(data) {                    
                    dataRecords.ajax.reload();
                }
            })
        } else {
            return false;
        }
    }); 
});

ajax_action.php

<?php
include_once 'config/Database.php';
include_once 'class/Records.php';

$database = new Database();
$db = $database->getConnection();

$record = new Records($db);

if(!empty($_POST['action']) && $_POST['action'] == 'listRecords') {
    $record->listRecords();
}
if(!empty($_POST['action']) && $_POST['action'] == 'addRecord') {   
    $record->Name = $_POST["Name"];
    $record->Type = $_POST["Type"]; 
    $record->IDNumber = $_POST["IDNumber"];
    $record->IDType = $_POST["IDType"];
    $record->IDState = $_POST["IDState"];
    $record->Phone = $_POST["Phone"];
    $record->Email = $_POST["Email"];
    $record->Address1 = $_POST["Address1"];
    $record->Address2 = $_POST["Address2"];
    $record->City = $_POST["City"];
    $record->State = $_POST["State"];
    $record->Zip = $_POST["Zip"];
    $record->addRecord();
}
if(!empty($_POST['action']) && $_POST['action'] == 'getRecord') {
    $record->VendorID = $_POST["VendorID"];
    $record->getRecord();
}
if(!empty($_POST['action']) && $_POST['action'] == 'updateRecord') {
    $record->VendorID = $_POST["VendorID"];
    $record->Name = $_POST["Name"];
    $record->Type = $_POST["Type"]; 
    $record->IDNumber = $_POST["IDNumber"];
    $record->IDType = $_POST["IDType"];
    $record->IDState = $_POST["IDState"];
    $record->Phone = $_POST["Phone"];
    $record->Email = $_POST["Email"];
    $record->Address1 = $_POST["Address1"];
    $record->Address2 = $_POST["Address2"];
    $record->City = $_POST["City"];
    $record->State = $_POST["State"];
    $record->Zip = $_POST["Zip"];
    $record->updateRecord();
}
if(!empty($_POST['action']) && $_POST['action'] == 'deleteRecord') {
    $record->VendorID = $_POST["VendorID"];
    $record->deleteRecord();
}
?>

Records.php

<?php
class Records { 
   
    private $recordsTable = 'vendor';
    public $VendorID;
    public $Name;
    public $Type;    
    public $IDNumber;
    public $IDType;
    public $IDState;
    public $Phone;
    public $Email;
    public $Address1;
    public $Address2;
    public $City;
    public $State;
    public $Zip;
    private $conn;
    
    public function __construct($db){
        $this->conn = $db;
    }       
    
    public function listRecords(){
        $columns = array('VendorID', 'Name', 'Type', 'IDNumber', 'IDType', 'IDState', 'Phone', 'Email', 'Address1', 'Address2', 'City', 'State', 'Zip');

        $sqlQuery = "SELECT * FROM ".$this->recordsTable." ";
        if(!empty($_POST["search"]["value"])){
            $sqlQuery .= 'where(Name LIKE "%'.$_POST["search"]["value"].'%" ';
            $sqlQuery .= ' OR Phone LIKE "%'.$_POST["search"]["value"].'%" ';           
            $sqlQuery .= ' OR Email LIKE "%'.$_POST["search"]["value"].'%" ';
            $sqlQuery .= ' OR IDNumber LIKE "%'.$_POST["search"]["value"].'%") ';           
        }
        
        if(!empty($_POST["order"])){
            $sqlQuery .= 'ORDER BY '.$columns[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
        } else {
            $sqlQuery .= 'ORDER BY VendorID DESC ';
        }
        
        if($_POST["length"] != -1){
            $sqlQuery .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
        }
        
        $stmt = $this->conn->prepare($sqlQuery);
        $stmt->execute();
        $result = $stmt->get_result();  
        
        $stmtTotal = $this->conn->prepare("SELECT * FROM ".$this->recordsTable);
        $stmtTotal->execute();
        $allResult = $stmtTotal->get_result();
        $allRecords = $allResult->num_rows;
        
        $displayRecords = $result->num_rows;
        $records = array();     
        while ($record = $result->fetch_assoc()) {              
            $rows = array();            
            $rows[] = $record['VendorID'];
            $rows[] = ucfirst($record['Name']);
            $rows[] = $record['Type'];
            $rows[] = $record['IDNumber'];  
            $rows[] = $record['IDType'];    
            $rows[] = $record['IDState'];   
            $rows[] = $record['Phone']; 
            $rows[] = $record['Email']; 
            $rows[] = $record['Address1'];
            $rows[] = $record['Address2'];
            $rows[] = $record['City'];
            $rows[] = $record['State'];
            $rows[] = $record['Zip'];
            $rows[] = '<button type="button" name="update" VendorID="'.$record["VendorID"].'" class="btn btn-warning btn-xs update">Update</button>';
            $rows[] = '<button type="button" name="delete" VendorID="'.$record["VendorID"].'" class="btn btn-danger btn-xs delete" >Delete</button>';
            $records[] = $rows;
        }
        
        $output = array(
            "draw"  =>  intval($_POST["draw"]),         
            "iTotalRecords" =>  $displayRecords,
            "iTotalDisplayRecords"  =>  $allRecords,
            "data"  =>  $records
        );
        
        echo json_encode($output);
    }
    
    public function getRecord(){
        if($this->VendorID) {
            $sqlQuery = "
                SELECT * FROM ".$this->recordsTable." 
                WHERE VendorID = ?";            
            $stmt = $this->conn->prepare($sqlQuery);
            $stmt->bind_param("i", $this->VendorID);    
            $stmt->execute();
            $result = $stmt->get_result();
            $record = $result->fetch_assoc();
            echo json_encode($record);
        }
    }
    public function updateRecord(){
        
        if($this->VendorID) {           
            
            $stmt = $this->conn->prepare("
            UPDATE ".$this->recordsTable." 
            SET Name = ?, Type = ?, IDNumber = ?, IDType = ?, IDState = ?, Phone = ?, Email = ?, Address1 = ?, Address2 = ?, City = ?, State = ?, Zip = ?
            WHERE VendorID = ?");

            $this->VendorID = htmlspecialchars(strip_tags($this->VendorID));     
            $this->Name = htmlspecialchars(strip_tags($this->Name));
            $this->Type = htmlspecialchars(strip_tags($this->Type));
            $this->IDNumber = htmlspecialchars(strip_tags($this->IDNumber));
            $this->IDType = htmlspecialchars(strip_tags($this->IDType));
            $this->IDState = htmlspecialchars(strip_tags($this->IDState));
            $this->Phone = htmlspecialchars(strip_tags($this->Phone));
            $this->Email = htmlspecialchars(strip_tags($this->Email));
            $this->Address1 = htmlspecialchars(strip_tags($this->Address1));
            $this->Address2 = htmlspecialchars(strip_tags($this->Address2));
            $this->City = htmlspecialchars(strip_tags($this->City));
            $this->State = htmlspecialchars(strip_tags($this->State));
            $this->Zip = htmlspecialchars(strip_tags($this->Zip));
                        
            $stmt->bind_param("sssssssssssii", $this->Name, $this->Type, $this->IDNumber, $this->IDType, $this->IDState, $this->Phone, $this->Email, $this->Address1, 
            $this->Address2, $this->City, $this->State, $this->Zip, $this->VendorID);
            
            if($stmt->execute()){
                return true;
    
        }   
    }
    public function addRecord(){
        
        if($this->Name) {

            $stmt = $this->conn->prepare("
            INSERT INTO ".$this->recordsTable."(`Name`, `Type`, `IDNumber`, `IDType`, `IDState`, `Phone`, `Email`, `Address1`, `Address2`, `City`, `State`, `Zip`)
            VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
            $this->Name = htmlspecialchars(strip_tags($this->Name));
            $this->Type = htmlspecialchars(strip_tags($this->Type));
            $this->IDNumber = htmlspecialchars(strip_tags($this->IDNumber));
            $this->IDType = htmlspecialchars(strip_tags($this->IDType));
            $this->IDState = htmlspecialchars(strip_tags($this->IDState));
            $this->Phone = htmlspecialchars(strip_tags($this->Phone));
            $this->Email = htmlspecialchars(strip_tags($this->Email));
            $this->Address1 = htmlspecialchars(strip_tags($this->Address1));
            $this->Address2 = htmlspecialchars(strip_tags($this->Address2));
            $this->City = htmlspecialchars(strip_tags($this->City));
            $this->State = htmlspecialchars(strip_tags($this->State));
            $this->Zip = htmlspecialchars(strip_tags($this->Zip));
                
            $stmt->bind_param("sssssssssssi", $this->Name, $this->Type, $this->IDNumber, $this->IDType, $this->IDState, $this->Phone, $this->Email, $this->Address1, $this->Address2, $this->City, $this->State, $this->Zip,);
            
            if($stmt->execute()){
                return true;
            }       
        }
    }
    public function deleteRecord(){
        if($this->VendorID) {           

            $stmt = $this->conn->prepare("
                DELETE FROM ".$this->recordsTable." 
                WHERE VendorID = ?");

            $this->VendorID = htmlspecialchars(strip_tags($this->VendorID));

            $stmt->bind_param("i", $this->VendorID);

            if($stmt->execute()){
                return true;
            }
        }
    }
}
?>

Edit: Added screenshot

Is this namespacing issue my problem or is it an IDE problem?

I have a namespacing notification on the PhpStorm IDE and I can’t see how to resolve it.

IDE

  • PhpStorm 2023.1

Structure

I have a class amongst various other classes by other vendors, my class sits in this folder:

/home/classes/vendor/namespaceOuter/namespaceInner/subnamespace

The autoloader.php file sits in /home/classes/

My class file sits inside the above folder, and is ClassFile.php. Within, this has the namespace set out as here:

<?php
Namespace namespaceOuternamespaceInnersubnamespaceClassFile;

use exception;
use PDOexception;

class ClassFile {
      ... 
}

Problem

The PhpStorm IDE tells me:

Namespace name doesn’t match the PSR-0/PSR-4 project structure

NOT a problem

  • The autoloader works perfectly.
  • The class and its children and peers all work perfectly on the live website, the issue seems purely with the IDE informing me we’re not following the PSR-0/PSR-4 .

Attempted Solutions

  • I have tried to change the namespace to make it call from root (namespaceOuternamespaceInnersubnamespaceClassFile;) within the Class file but this doesn’t remove the notification.

  • I have tried to use the suggested fix by the IDE which in fact makes a bunch of new child folders in the current class’ folder (/home/classes/vendor/namespaceOuter/namespaceInner/subnamespace/namespaceOuter/namespaceInner/subnamespace/ClassFile.php) which is clearly impractical and wrong.

  • Other established classes (such as PHPMailer) within the vendor/ folder do not have the same notice on their class files.

Reading

I have read the PHP Namespacing documentation as well as the PSR-4 documentation which includes this example:

Fully Qualified Class Name Namespace Prefix Base Directory Resulting File Path
SymfonyCoreRequest SymfonyCore ./vendor/Symfony/Core/ ./vendor/Symfony/Core/Request.php

While this IS NOT a Symfony project, the inconsistency between qualified namespace and file path implies this is not an issue.

Fully Qualified Class Name Namespace Prefix Base Directory Resulting File Path
namespaceOuternamespaceInnersubnamespaceClassFile.php namespaceOuternamespaceInnersubnamespace classes/vendor/ ???

Question

Is this namespacing incorrect somehow or is there an issue with the PHPStorm IDE suggestion (I believe so) — if so, how can I check/ update / confirm / fix this?

Thanks

Elementor CSS load in footer after using get_builder_content_for_display($id)

My goal is to build Elementor Header builder, i have created a custom post type and design some block using elementor and then with help of this following code display anywhere.

echo ElementorPlugin::instance()->frontend->get_builder_content_for_display($template_id);

but the issue is when i use it as a header in few page [Like: blog, archive, 404] CSS loads in footer that’s why some issue create because of CSS priority. but if i edit some page with elementor and see the footer and css it load properly in header.

changing style of the active element on a WP PHP Menu

I am creating a menu using this function:

function top_nav_menu( $theme_location ) {
    if ( ($theme_location) && ($locations = get_nav_menu_locations()) && isset($locations[$theme_location]) ) {
        $menu = get_term( $locations[$theme_location], 'nav_menu' );
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        $menu_list  = '<nav class="header__titlemenu__menu">' ."n";
            $menu_list  .= '<ul class="heading4">' ."n";
            foreach( $menu_items as $key => $menu_item ) {
                $menu_list .= '<li class="mr">' ."n";
                $menu_list .= '<a href="' . $menu_item->url . '" class="list">' . strtoupper($menu_item->title) . '</a>' ."n";
                $menu_list .= '</li>' ."n";
            }
            $menu_list .= '</ul>' ."n";
        $menu_list .= '</nav>' ."n";
    } else {
        $menu_list = '<!-- no menu defined in location "'.$theme_location.'" -->';
    }
    echo $menu_list;
}

the problem is I want to highlight the current page I am on the menu but it seems not possible due when I apply a pseudoclass it applies to all the menu elements, maybe with a function or similar will be able to achieve that?

Symfony doctrine mongodb changing field type to object instead of array after removing a string element from array

It is more like a php issue instead of doctrine mongodb. I feel like I’m doing it wrong. So I have this Attendance data which I’m getting from db. This is how the data looks like in the db:

{
  id: '1',
  tags: {
    item: {
      active: true,
      value: ['regular', 'irregular']
    } 
  }
}

I have this method which takes two parameter, id and selectedValues. SelectedValues is an array of strings. When I call the method, it should first fetch the attendance data and then remove an element from the above object’s value array if the element doesn’t exist in selectedValues array. For example, let’s say selectedValues: ['irregular'], so then after calling the method, the object will have value array to be ['irregular'] because regular doesnt exist in selectedValus.

Another example would be if the object above has value array of ['regular'] and selectedValues array is ['irregular'], then after calling the method the values array will be [].

Right now when I call the method, both the example works fine but somehow the first example changes it to an object instead of keeping it as an array in the db. Something like { 0: 'irregular' }. Which I don’t want. I want array of strings all the time.

Here’s the code:

public function removeElementFromTagsValue(string $id, array $selectedValues)
  {
    $attendance = $this->repository->findOneBy([ 'id' => new ObjectId($id) ]);

    $tags = $attendance->getTags();
    $tagValues = $tags['item']['value'];

      // remove
      foreach ($tagValues as $key => $value) {
        if (!in_array($value, $selectedValues)) {
          unset($tagValues[$key]);
        }
      }

      $tags['item']['value'] = $tagValues;
      $attendance->setTags($tags);

      $this->documentManager->persist($attendance);
      $this->documentManager->flush();

      return $attendance;
  }

PHP – most convenient minification library [closed]

I am using minification library to use within my Symfony project to minify the mixed content of my email templates. I did some investigations to find a minification library that fits the best and currently using matthiasmullie/minify but it also removes spaces after commas in the content part.

Is there any other library that someone is using but that is keeping content intact?

Thanks

Why does nginx (or php) turn spaces into underscores? [duplicate]

I have Nginx setup with a try_files statement:

location / {
        try_files $uri $uri/ @php;
}
location @php {
     rewrite ^/(.*)$ /index.php?$1 last;
}

So www.example.com/thisfolder is handled by my index.php with a $_GET['thisfolder'], upon which PHP can act. This works fine.
However, the path in the URL can contain spaces like so: www.example.com/this folder.
In that case I get a $_GET['this_folder'] (with an underscore), instead of the $_GET['this folder'] that I expected.
Encoding the URL as www.example.com/this%20folder does not change anything. Is the space-to-underscore-replacement done by PHP or by Nginx and how do I get rid of it so PHP gets the parameter with a space in the name?