I am designing a website using Nodejs and Php and want to display latest news on internet related to AI on my website. Content may be video or article. How do i get the live feed? Secondly, using code can I search articles in ieee or ResearchGate and automatically display them on website?
Category: PHP
Category Added in a WPeMatico Campaign
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"
Bringing a Form from PHP script to WordPress based website’s home Page
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
Can I collect explode then explode again? – Laravel 8
I’m trying to create data save variable using a text file. I read that the collect function in laravel is the right choice for managing the data.
Here is the data saved after I exploded with PHP_EOL :
What I want to do is explode once more per array with “|”, so my code is like this but it can’t.
$temps=explode(PHP_EOL,$note);
$isi=collect([
explode('|',$temps)
]);
This code can only be applied if it is accompanied by a manual array like this :
$isi=collect([
explode('|',$temps[0]),
explode('|',$temps[2])
]);
Please help.
Cakephp 4 not running on Ubuntu 20.3
After installing and creating a new CakePHP app using composer, I am trying to run the app on my browser using bin/cake server
.
I get these errors:
Warning: cake_core cache was unable to write ‘cake_dev_eng’ to File cache in /usr/share/php/Cake/Cache/Cache.php on line 327
PHP Warning: /usr/share/php/Cake/Console/Templates/skel/tmp/cache/persistent/ is not writable in /usr/share/php/Cake/Cache/Engine/FileEngine.php on line 389
Please can anyone help me with resolving these issues? I am new to Linux.
Thanks in advance.
WordPress does not detect bootstrap and Jquery
I have an application that I’m trying to include in a wordpress page, I passed it the include of the index.php file and everything is displayed but when it looks for the JQuery and Bootstrap files for the style these are not detected.
The style files are located in the same folder as the index file and I pass them as follows (they are just examples):
<link rel="stylesheet" href="include/bootstrap4/css/bootstrap-select.min.css">
<link rel="stylesheet" href="include/bootstrap4/css/bootstrap.min.css">
<link rel="stylesheet" href="include/bootstrap4/other/jquery-ui.css">
<script src="include/bootstrap4/other/jquery-3.3.1.min.js"></script>
Also I tried to include Bootstrap with cnd and the style is detected but with Jqueys still nothing.
The application without the jquery files does not work, can anyone tell me how I can include bootstrap and Jquery in the page?