Detele from DB with button [closed]

I want to delete info by click a button. So from select menu when i chose number from 1- 20 and push button NEXT is shows me “all the orders in that table from DB” When I push the button Finish in theory should delete all orders on the table i choose in DB. When i push the buutton it give me sql error.PLS help.

<?php
    require_once("connect.php");
    echo '<pre>'; print_r($_POST); echo '</pre>';
    
    if (isset($_POST['buton']))
    {   
        $tablenumber=$_POST['number'];
        $sql="SELECT orders.code,menu.name,orders.count,menu.price, orders.count*menu.price as Total 
        FROM orders,menu WHERE table_number=$tablenumber and orders.code=menu.code";    
        $quer=mysqli_query($conn,$sql)or die ('error sql');
        $num=mysqli_num_rows($quer);

        $sql2="SELECT  SUM(orders.count*menu.price) as TotalPrice 
        FROM orders,menu WHERE table_number=$tablenumber and orders.code=menu.code";    
        $quer2=mysqli_query($conn,$sql2)or die ('error sql2');      
    }
        if (isset($_POST['Finish']))    
        {   
            $tablenumber=$_POST['number'];
    
        $sql3=" DELETE FROM orders WHERE table_number=$tablenumber";
        $quer3=mysqli_query($conn,$sql3)or die ('error 1sql');
        }
    
?>
<html>
<form action="login.php" method="post">
<span style="display:flex; justify-content:flex-end; width:100%; padding:0;">
    <input type="submit" value="Exit"/>
</form>
</span>
        <style>
            body {background-color: #87CEEB;}
        </style>
    <head>
        <title>Factura</title>
        <!---<meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="dff.css"/>  !--->
    </head>
    <body>  
        <form id="frmFactura" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
                
           <div id="cabeceraFactura">
                <br>
                <SELECT NAME="number" size="1">
                    <option value="---">---</option>
                    <?php
                        for($i=1;$i<=20;$i++)
                        { echo "<option value=".$i.">".$i."</option>";}
                    ?>
                </SELECT>               
                <input type='submit' name='buton' value="NEXT"/>    
            </div>
            <br>
            <table id ="detalle" border="2" width="3" cellspacing="2" cellpadding="1">
                <thead>
                    <tr>
                     <th>Name</th>
                        <th>Count</th>
                        <th>Unit price</th>
                        <th>Total</th>
                    </tr>
                </thead>
                <tbody>
                <?php
                
                    if(isset($_POST['buton']))
                    {    while ($resul=mysqli_fetch_array($quer) )  
                        {   echo '
                    <tr>
                        <td><input class="descrip" type="text" name="naimenovanie" value="'.$resul["name"].'" disabled=""/></td>
                        <td><input class="cant" type="text" name="kolichestvo"  value="'.$resul["count"].'" disabled=""/></td>
                        <td><input class="vunit"type="text"  name="cena" value="'.$resul["price"].'" disabled=""/></td>
                        <td><input class="totPro" type="text"  name="obstho" value="'.$resul["Total"].'" disabled=""/></td>     
                    </tr>
                        ';
                        }
                    }       
                ?>
                </tbody>
            </table> 
            <br>
            <div class="Resultados">
                <table border="2" width="3" cellspacing="2" cellpadding="1">                  
                    <tr>
                        <td><label id="lbl">TotalPrice</label></td>
                        <?php
                            if(isset($_POST['buton'])) $resul2=mysqli_fetch_array($quer2);
                        ?>
                        <td><input class="totPro" type ="text" value="<?php if(isset($_POST['buton'])) 
                         echo $resul2['TotalPrice'];?>"  disabled=""/> </td>
                     
                    </tr>   
                </table>
                <br>
                <button onclick="window.print()" width="200">Print </button>    
                    <input type="submit"  name= "Finish" value = "Finish">
            </div>  
        </form>                                         
    </body>
</html>

please need to fix this i cant add in my database [duplicate]

Notice: Undefined variable: title in C:xampphtdocssampleappadd_record.php on line 19

Notice: Undefined variable: task in C:xampphtdocssampleappadd_record.php on line 19
An error has been occured!PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘title’ cannot be null in C:xampphtdocssampleappadd_record.php:20 Stack trace: #0 C:xampphtdocssampleappadd_record.php(20): PDOStatement->execute(Array) #1 {main

This is my code

Check if name already exist in database but Id is not same in Laravel 6

Properties Table

id name
1 abc
2 xyz

I want to check if the name exists during edit but if it is the same Property then ignore it.

When I want to insert using this code

$ruls = [
        'property_type' => 'required',
        'project_name' => 'required|unique:properties,name',
    ];
$request->validate($ruls, []);     

and I want to using same validation when property edit like

select name from properties where name = name and id != 1

Please help me to solve this issue.

How to delete the entire row in the database from html table instead of deleting entire table in the database

I have added delete button to the html table on each row and when clicked on delete button the entire row should be deleted but instead whole table in the database is being deleted.

here is my code for admin.php

    <div class="container mt-3 ml-3">
<table class="table">
    <thead>
    <tr>
        <th>S.No</th>
        <th>Name</th>
        <th>Email</th>
        <th>Rating</th>
        <th>Review</th>
        <th>Image</th>
        <th>Suggestion</th>
        <th>NPS</th>
        <th>Delete</th>
    </tr>
    </thead>
    <tbody class="table-warning">

<?php
include 'database_conn.php';      // makes db connection

$sql = "SELECT feedbackID, name, email, rating, review, image, suggestion, nps
        FROM feedback 
        ORDER BY feedbackID Desc";
$queryResult = $dbConn->query($sql);

// Check for and handle query failure
if($queryResult === false) {
    echo "<p>Query failed: ".$dbConn->error."</p>n";
    exit;
}
// Otherwise fetch all the rows returned by the query one by one
else {
    if ($queryResult->num_rows > 0) {
        while ($rowObj = $queryResult->fetch_object()) {
            echo "<tr>
                  <td>{$rowObj->feedbackID}</td>
                  <td>{$rowObj->name}</td>
                  <td>{$rowObj->email}</td>
                  <td>{$rowObj->rating}</td>
                  <td>{$rowObj->review}</td>
                  <td>{$rowObj->image}</td>
                  <td>{$rowObj->suggestion}</td>
                  <td>{$rowObj->nps}</td>
                  <td><a id='delete' href=delete.php?id={$rowObj->feedbackID}>Delete</a></td>
                  

              ";
        }

    }
}
?>

</tr>
    </tbody>
</table>
</div>

And here my code for delete.php. I think there is something wrong in the sql query I made.

    <?php
include 'database_conn.php';      // makes db connection


$sql = "DELETE FROM feedback WHERE feedbackID=feedbackID";

if ($dbConn->query($sql) === TRUE) {
    echo "Record deleted successfully. Please go to Customer Feedback Page by clicking"; echo "<a href='http://unn-w18031735.newnumyspace.co.uk/feedback/admin.php'> here</a>";
} else {
    echo "Error deleting record: " . $dbConn->error;
}

$dbConn->close();
?>

unzip file with vbs or powershell with password

I tried to find but without success.
I can unzip a ZIP file with batch FILE but it does not work when I have a password

These are the scripts I use:
One is bat and vbs:

cd /d %~dp0
Call :UnZipFile "c:ver" "c:tempverupdate.zip"
exit /b

:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs%  echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%



The second in powershell:
PS1 file :

$jennyPath = gci -filter "test.zip" -recurse | Select-Object -ExpandProperty FullName

# step 2: unzip to current folder
$ShellExp = New-Object -ComObject Shell.Application
$zip = $ShellExp.NameSpace($jennyPath)
$pwd = (Get-Item -Path ".").FullName
$dest = $ShellExp.NameSpace($pwd)
$dest.Copyhere($zip.items(), 0x14) 


bat file :
powershell -executionpolicy bypass -Command "./unzip.ps1"

Getting the “bobot” value of the selected option on a dynamic form using PHP

I’m having a problem getting the selected weight value on a dynamic form I’m creating. Here’s the code for the get_recomendation.php form:

<form action="./get-recomendation-admin.php" method="POST" class="row justify-content-center">
   <?php $kriteria = $connection->query("SELECT * FROM kriteria"); while ($data = $kriteria->fetch_assoc()): ?>
       <div class="col-12 my-4 my-options">
           <label for="kriteria" class="form-label"><?=$data["nama"]?></label>
           <input type="hidden" class="form-control" id="id_kriteria" name="id_kriteria" readonly value="<?php echo $data['id_kriteria']; ?>">
           <input type="hidden" class="form-control" id="nama_kriteria" name="nama_kriteria" readonly value="<?php echo $data['nama']; ?>">
               <select class="form-select" id="bobot_kriteria" required="">
                    <option value="" disabled selected>Pilih Sub Kriteria</option>
                     <?php $t_kriteria = $connection->query("SELECT * FROM tingkat_kriteria"); while ($row = $t_kriteria->fetch_assoc()): ?>
                         <option value="<?=$row["bobot"]?>"><?=$row["nama"]?></option>
                     <?php endwhile; ?>
               </select>
       </div>
    <?php endwhile; ?>

    <div class="d-flex justify-content-center my-5">
         <button class="btn btn-dark mb-3 shadow-button fs-6 px-5 py-3" type="submit">Cari Rekomendasi</button>
    </div>
</form>

I tried to do a var_dump using the following code

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        var_dump($_POST['nama_kriteria']);
        var_dump($_POST['bobot_kriteria']); 
    }

result

string(5) "Harga"
Notice: Undefined index: bobot_kriteria in E:Program Filesxampphtdocsxxxxxxxxget-recomendation-admin.php on line 12
NULL

As for the output I want it’s like

Jenis Processor
10
Kapasitas RAM
20
XXXXX
XX
....

For the database I use like this

table tingkat_kriteria

| id    | nama            | bobot |
|:----: |:---------------:|:-----:|
| 1     | Sangat Penting  | 30    |
| 2     | Cukup Penting   | 25    |
| 3     | Cukup           | 20    |
| 4     | Kurang Penting  | 15    |
| 5     | Tidak Penting   | 10    |

and for the criteria table like this

table kriteria

| id    | nama            |
|:----: |:---------------:|
| 2     | Jenis Processor |
| 3     | Kapasitas RAM   |
| 4     | Jumlah Drive    |
| 8     | Harga           |

Selecting range of records from each category

I’ve a table called dept with dept_id as foreign key in participants table. Training is to be in 4 batches (A, B, C and D) the participants of the training are coming from 5 departments.

I need all the departments to be represented in each of the batches. How do I select 20 participants from each dept per batch? So that for each batches I will have 100 participants.
NOTE: I am not looking at any specific order for the selection, I t can be random or not.

I’ve this query so far:

SELECT dept.dept_name,
       participants.full_name,
       participants.email,
       participants.phone_number
FROM   participants
       JOIN dept
         ON participants.dept_id = dept.dept_id
WHERE  dept_name IN ( "lifestock", "fishery", "media", "foodtech", "extension" )
ORDER  BY participants_id
LIMIT  20;

Problem with post image url in woocomrece api

Hi I’m new in woocomrece API
and I want to send an image for my product, but every time I refresh the code with the same URL link new image media add to my WordPress media with a new link, and after like 10 times I have 10 duplicates of an image in media

<?php
$data = [
    'name' => $name,
    'type' => 'variable',
    'regular_price' => '50',
    'description' => $description,
    'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
    'categories' => [
        [
            'id' => $id_19
        ],
        [
            'id' => $id_23
        ]
    ],
    
    'images' => [
       
        
        [
            
            'src' => 'http://localhost/wordpress/wp-content/uploads/2022/03/arian-logo-1.png',

        ]
    ],
    'attributes' => [
        [
            'name' => 'color',
            'position' => 0,
            'visible' => true,
            'variation' => true,
            'options' => [
                'Black',
                'Green'
            ]
        ],
        [
            'name' => 'Size',
            'position' => 0,
            'visible' => true,
            'variation' => true,
            'options' => [
                'S',
                'M'
            ]
        ]
    ],
    'default_attributes' => [
        [
            'name' => 'color',
            'option' => 'Black'
        ],
        [
            'name' => 'Size',
            'option' => 'S'
        ]
    ]
];
($woocommerce->post('products', $data));
?>

Cannot extract columns from array using pluck

I’m trying to extract the id value from a list of associative array, this is the value of $request->post('files'):

array:2 [
  0 => array:2 [
    "id" => "21"
    "name" => "aviary-image-1429352137570.jpeg"
  ]
  1 => array:2 [
    "id" => "22"
    "name" => "1.jpg"
  ]
]

I tried:

$fileList = $request->post('files');
dd($fileList->pluck('id'));

But this returns:

Expected type ‘object’. Found ‘string|array|null’

So for the moment to fix this I have created a loop which iterates over the array and get only the id.

The expected result is: [21, 22]

Is there any way to do this without loop?

how to change the local directory from htdocs to my project folder XAmmp

I am currently setting up wordpress applications of my client in my local. Client is using Mammp paid version on a mac, and I am using Xammp on my pc. He is unable to guide me on how to do it. What I have is the code base repo of my php application, a .sql data dump file which the client wants me to import into mysql using command line. I did this using command line and I can see the db under databases in php my admin.
How do I proceed from here, how do i let “wordpress connect to the db”?
I followed the installation process for wordpress and unzipped the entire content of wordpress zip to my project folder which i placed inside htdocs folder.
Client said i have to change the root folder from htdocs in xammp to my project location.
I tried this for changing root folder:

Go to C:xamppapacheconfhttpd.conf.
Open httpd.conf.
Find tag : DocumentRoot “C:/xampp/htdocs”
Edit tag to : DocumentRoot “C:/xampp/htdocs/myproject/web”
Now find tag and change it to < Directory “C:/xampp/htdocs/myproject/web” >
Restart Your Apache.

It didn’t work.

SAML private key leak

I have encountered a data leak recently and it turns out source code got leaked.
I’m analysing everything that might come back to bite me and of the things is SAML private key.

Could a private key be used with malicious intent? I understand it gives the ability to decrypt SAML requests and the possibility to create some aswell, but I am far from knowledgable on the subject.

Thanks!

Z

How to calculate and update sales price in woocommerce product page

I inserted two radio buttons as product add ons by using the following to calculate extra packaging cost. But I have two problems.

First instead of getting the value of my custom field eg 4.35 it gets a value of 4.00.

Second how can I update the sales price in my product page when I choose an option

function add_custom_fees_before_add_to_cart() {
    global $product;

    $myfee = floatval(get_post_meta(get_the_ID(), '_skrprom', TRUE)) + floatval(0.90);

    $args = array(
        'type' => 'radio',
        'class' => array( 'form-row-wide' ),
        'options' => array(
        '' => 'Τηλεφωνική Παραγγελία',
        $myfee => 'Έξοδα Συσκευασίας '.$myfee.'€',
    ),
    'default' => ''
);
?>
<div class="custom-fees-wrap">
    <label for="iconic-engraving"><?php _e( 'Customize Your Order!', 'textdomain' ); ?></label>
    <?php woocommerce_form_field( 'custom_fees', $args, '' ); ?>
</div>
<?php
}

add_action( 'woocommerce_before_add_to_cart_button', 'add_custom_fees_before_add_to_cart', 99 );


function save_value_add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
$custom_fees = filter_input( INPUT_POST, 'custom_fees' );

if ( empty( $custom_fees ) ) {
    return $cart_item_data;
}

$cart_item_data['custom_fees'] = $custom_fees;

return $cart_item_data;
}

add_filter( 'woocommerce_add_cart_item_data', 'save_value_add_cart_item_data', 99, 3 );

function calculate_add_cart_fee() {
   global $woocommerce;
   $cart_items = $woocommerce->cart->get_cart();
   foreach( $cart_items as $key => $item ) { 
      if( !isset( $item['custom_fees'] ) && empty( $item['custom_fees'] ) ) continue;
    $woocommerce->cart->add_fee( __('Έξοδα Συσκευασίας', 'textdomain'), $item['custom_fees'] );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'calculate_add_cart_fee', 99 );

Rewrite rule in plugin for permalink

I have plugin which is active on de page (permalink):
site.com/plugininfo/?item_id=100

I want to add in plugin rewrite rule for this url’s:
site.com/items/blabla/100/

“blabla” will be each time different.

I have tried different solutions but without success.

function when_rewrite_rules( $wp_rewrite ) {
  $new_rules = array();
  $new_rules['items/([^/]+)/([^/]+)/?$'] = 'plugininfo/?item_id=$matches[2]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules','when_rewrite_rules');

seems that you can not rewrite url to direct to the permalink?

if I change code to

$new_rules['items/([^/]+)/([^/]+)/?$'] = 'index.php?p=500&item_id=$matches[2]';

500 is id of page, then is working but visitor get redirected from site.com/items/blabla/100/ to site.com/plugininfo/?item_id=100

Of course i want that visitor stay at url site.com/items/blabla/100/

Any solutions?
Thanks

Pedja