AndrisP 193 Posting Pro in Training

And do not redefine svg objects on each use it, reuse defined objects instead e.g.
css

#svg_sources {
    position: fixed;
    top: 0;
    left: 0;
}

html

<html xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg">
<head>
...
</head>
<body>
<div id="svg_sources">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="0" height="0">
    <defs>
        <g id="menu_lines">
            <line x1="3" y1="0" x2="3.01" y2="0" />
            <line x1="8" y1="0" x2="21" y2="0" />
        </g>
        <g id="menu_icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-list">
            <use xlink:href="#menu_lines" transform="translate(0,6)" />
            <use xlink:href="#menu_lines" transform="translate(0,12)" />
            <use xlink:href="#menu_lines" transform="translate(0,18)" />
        </g>
        <polyline id="menu_bullet" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-list" points="9 18 15 12 9 6" />
    </defs>
</svg>
</div>

php

function print_recursive($list){
    echo '<ul style="list-style-type:none">';
    foreach($list as $item){
        echo '<li id="'.$item['id'].'"><a href="javacript:void(0);"><svg width="24" height="24" viewBox="0 0 24 24"><use xlink:href="#menu_bullet" /></svg>'.$item['text'];
        if( isset($item['children']) ){
            print_recursive($item['children']);
        }
        echo '</li>';
    }
    echo '</ul>';
}
echo '<svg width="24" height="24" viewBox="0 0 24 24"><use xlink:href="#menu_icon" /></svg>';
print_recursive($list);
AndrisP 193 Posting Pro in Training

Use recursive printing e.g.

<?php
function print_recursive($list){
    echo '<ul>';
    foreach($list as $item){
        echo '<li id="'.$item['id'].'">'.$item['text'];
        if( isset($item['children']) ){
            print_recursive($item['children']);
        }
        echo '</li>';
    }
    echo '</ul>';
}
print_recursive($list);
?>
AndrisP 193 Posting Pro in Training

I think You need normalize DB-tables for first.

create table Pensyarah(
    IDPensyarah integer not null primary key auto_increment
  , IDUser varchar(50) not null
  , NamaPensyarah varchar(100) not null
  , Email varchar(50) not null
  , NoTel varchar(11) not null
);

create table Kursus(
    IDKursus integer not null primary key auto_increment
  , Semester integer not null
  , KodKursus varchar(50) not null
  , NamaKursus varchar(50) not null
);

create table PensyarahKursusRefs(
    PensyarahKursus integer not null primary key auto_increment
  , IDPensyarah integer not null
  , IDKursus integer not null
  , constraint IDPens_IDKurs_Sem_UQ unique key (Semester,IDPensyarah,IDKursus)
  , constraint Pensyarah_FK foreign key (IDPensyarah) references Pensyarah(IDPensyarah)
  , constraint Kursus_FK foreign key (IDKursus) references Kursus(IDKursus)
);

Then creat view for convenient select list of "Kursus" in one column
like in sample:

create or replace view PensyarahKursus as
select
    p.IDUser
  , p.NamaPensyarah
  , p.Email
  , p.NoTel
  , k.Semester
  , group_concat(k.KodKursus separator ', ') kursusList
from Pensyarah p
left join PensyarahKursusRefs pkr using(IDPensyarah)
left join Kursus k using(IDKursus)
group by
    p.IDUser
  , p.NamaPensyarah
  , p.Email
  , p.NoTel
  , k.Semester
;

You can create procedure for convenient reference inserting:

delimiter $$
create procedure set_Kursus_ref(
    in p_IDUser varchar(50)
  , in p_KodKursus varchar(50)
)
begin
  insert into PensyarahKursusRefs(IDPensyarah,IDKursus) values (
      (select p.IDPensyarah from Pensyarah p where p.IDUser = p_IDUser)
    , (select k.IDKursus from Kursus k where k.KodKursus = p_KodKursus)
  );
end; $$
delimiter ;

Then sample insert and select:

insert into Pensyarah(IDUser,NamaPensyarah,Email,NoTel)
  values ('sample_ID_user_1','sample_Nama_1','sample.1@sapmle.com','11111111111');
insert into Pensyarah(IDUser,NamaPensyarah,Email,NoTel)
  values ('sample_ID_user_2','sample_Nama_2','sample.2@sapmle.com','22222222222');
insert into Pensyarah(IDUser,NamaPensyarah,Email,NoTel)
  values ('sample_ID_user_3','sample_Nama_3','sample.3@sapmle.com','33333333333');

insert into Kursus(Semester,KodKursus,NamaKursus) values (1,'KK-1','KursusNama-1');
insert into Kursus(Semester,KodKursus,NamaKursus) values …
AndrisP 193 Posting Pro in Training

In your examples 2 and 3 are missing final } on while loop

Ant_426 commented: Thanks for spotting that, Andris. Unfortunately that is not the problem though, that was just a copy/paste error on my part. +0
AndrisP 193 Posting Pro in Training

What about require - files exists on defined path?

AndrisP 193 Posting Pro in Training

I think your mistake is comparing string and number

SQLite.png

You should be use cast(strftime('%Y', HireDate) as number)<2003

AndrisP 193 Posting Pro in Training

I think your mistake is mixed use of variable names "searchdata" and "searchname"

AndrisP 193 Posting Pro in Training

I'm sorry - check your PHP version. Extension "mysql_..." depraceted in PHP 5.5.0 and removed in PHP 7 mysql_query

AndrisP 193 Posting Pro in Training

For first check your MySQL version

select version() from dual;

Because all "mysql_..." in current (MySQL 8.0.) is deprecated - probably you should be use "mysqli_..." instead

AndrisP 193 Posting Pro in Training
  1. I recomend use prepared statement instead of directly put user input data to SQL query.
  2. Use SEND_LONG_DATA to store blob into database.
AndrisP 193 Posting Pro in Training

Better solution is create view with join nested tables and then search in view

AndrisP 193 Posting Pro in Training

if you want to denormalize SQL table for search then you think wrong

AndrisP 193 Posting Pro in Training

Use CSS e.g.

input[type="button"][value="one"] {
    background: blue;
}
input[type="button"][value="two"] {
    background: red;
}
AndrisP 193 Posting Pro in Training

Radio buttons let a user select ONLY ONE of a limited number of choices
Use same attribute "name" but array of values use as attribute "value" e.g.

var div = document.createElement('div');
div.setAttribute('id','my_div');
document.body.appendChild(div);

function addradio(){
    const names=["abi","sam","tom"];
    names.forEach(
        function(curr){
            document.getElementById("my_div").innerHTML+='<br/>'
            +'<input type="radio" id="my_'+curr+'" name="names" value="'+curr+'" />'
            +'<label for="my_'+curr+'">'+curr+'</label>';
        }
    );
}

addradio();
AndrisP 193 Posting Pro in Training

Your mistake is comma after $_POST['JENIS_PERMINTAAN']. If you want to handle as array $_POST['JENIS_PERMINTAAN'], reverse_tanggal($_POST['TGL_PERMINTAAN']) then include it in square brackets

foreach([$_POST['JENIS_PERMINTAAN'], reverse_tanggal($_POST['TGL_PERMINTAAN'])] as $idx=>$val){
AndrisP 193 Posting Pro in Training

Manage date in SQL query:

$id = $_GET['id'];
$sql = "UPDATE apparatuur SET inlever_datum = date(current_date()+7), uitleen_datum = NOW() WHERE id= ? ";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $id);
$status = $stmt->execute();
AndrisP 193 Posting Pro in Training

Create event in database MySQL event create

AndrisP 193 Posting Pro in Training

and another question - why you do not use pathinfo($file,PATHINFO_EXTENSION) insead of substr($file, strrpos($file, '.') + 1) in line 4?

AndrisP 193 Posting Pro in Training

Do not need write script for this. Actually its a single line command e.g.
You have directory dir1 which contains multiple files and dir2 which is target to copy cp dir1/* dir2/ copy all files

AndrisP 193 Posting Pro in Training

a small correction to my post

    $ip = filter_input(INPUT_SERVER,'REMOTE_ADDR',FILTER_VALIDATE_IP);
    $stmt->execute([$ip,$ip,$ip]);
AndrisP 193 Posting Pro in Training

You can insert all these values witout trigger e.g. use prepared statement:

insert into download (
    `ADDRESS`
    ,`ip_address`
    ,`vrefer`
)
select
    ?
    ,inet_aton(?)
    ,(select id from `ip_lookup` where inet_aton(?) between ip_lookup.start and ip_lookup.end limit 1)
;

and execute with array 3 times pass IP

$stmt->execute(['127.0.0.1','127.0.0.1','127.0.0.1']);

or pure SQL version:

set @ip='127.0.0.1';
insert into download (
    `ADDRESS`
    ,`ip_address`
    ,`vrefer`
)
select
    @ip
    ,inet_aton(@ip)
    ,(select id from `ip_lookup` where inet_aton(@ip) between ip_lookup.start and ip_lookup.end limit 1)
;
AndrisP 193 Posting Pro in Training

Don't need declare - select values direct to fields

DELIMITER //
CREATE TRIGGER download_ins  BEFORE INSERT ON download 
    FOR EACH ROW begin
    set new.ip_address = inet_aton(new.`ADDRESS`);
    set new.vrefer=(select id
            from `ip_lookup`
            where inet_aton(new.`ADDRESS`) between ip_lookup.start and ip_lookup.end
            limit 1
        );
END; //
DELIMITER ;
AndrisP 193 Posting Pro in Training

Get value from array by key $temp['IP_ADDRESS'] but use of between in your code is wrong - should be convert by INET_ATON

AndrisP 193 Posting Pro in Training

get totals:

select
    ifnull(t.product_id,'Total') product_id
    ,sum(t.sale) sale
    ,sum(t.purchase) purchase
from (
    SELECT I.product_id, 
        ifnull(S.sale, 0) AS sale, 
        ifnull(P.purchase, 0) AS purchase
    FROM product I
        LEFT JOIN (
            SELECT product_id, SUM(quantity) AS sale
            FROM order_item 
            GROUP BY product_id
        ) S ON S.product_id = I.product_id
        LEFT JOIN (
            SELECT product_id, SUM(quantity) AS purchase
            FROM pur_item
            GROUP BY product_id
        ) P ON P.product_id = I.product_id
    where S.sale is not null or P.purchase is not null
) t
group by t.product_id with rollup
;
AndrisP 193 Posting Pro in Training

Sorry suquery will have to be used here but your join is incorrect - for first select all product ID's from product table then join sale and purcase

select
    p.product_id
    ,s.sale
    ,c.purchase
from (
    select product_id from product
) p
left join (
    select product_id, sum(quantity) sale from order_item group by product_id
) s on s.product_id = p.product_id
left join (
    select product_id, sum(quantity) purchase from pur_item group by product_id
) c on c.product_id = p.product_id
where s.sale is not null or c.purchase is not null;
AndrisP 193 Posting Pro in Training

For first check correct result using separate queries:

select product_id, sum(quantity) from pur_item group by product_id;
select product_id, sum(quantity) from order_item group by product_id;

and i recommend do not use subqueries if it possible - it's too slow

AndrisP 193 Posting Pro in Training

I recommend use join instead of subquery if possible because join works faster. I think you have another table e.g. products which contains all product id. Select product_id from products and left join sale and purchase. Where clause exclude null values e.g.

select
    p.product_id
    ,sum(s.quantity) sale
    ,sum(c.quantity) purchase
from products p
left join purchase c on c.product_id = p.product_id
left join sale s on s.product_id = p.product_id
where c.quantity is not null or s.quantity is not null
group by p.product_id;

also may add rollup to get total sales and total purchases

select
    coalesce(p.product_id,'Total')
    ,sum(s.quantity) sale
    ,sum(c.quantity) purchase
from products p
left join purchase c on c.product_id = p.product_id
left join sale s on s.product_id = p.product_id
where c.quantity is not null or s.quantity is not null
group by p.product_id with rollup;
nishita_1 commented: dear sir, Thank you you are really helpful. Thanks sir +0
AndrisP 193 Posting Pro in Training

I'm not sure you can get it exactly. Oracle DB and Postgres have a returning clause e.g. insert into table(id,val_1,val_2) returning id into variable; but MySQL doesn't

AndrisP 193 Posting Pro in Training

E.g.

drop table if exists test_table;
create table test_table(
    id int not null auto_increment primary key
    ,test varchar(30) null
    ,unique key (test)
);
insert into test_table(test) values('1 sample string');
insert into test_table(test) values('2 sample string');
insert into test_table(test) values('3 sample string');

when you try to repeat any of inserts above - it raise error unique key constraint but if you try any of below inserts

insert into test_table values(1,'1 sample string') 
    on duplicate key update id = last_insert_id(id);
insert into test_table values(2,'2 sample string') 
    on duplicate key update id = last_insert_id(id);
insert into test_table values(3,'3 sample string') 
    on duplicate key update id = last_insert_id(id);

then 0 rows affected without errors. Check select last_insert_id(); after each of last 3 insert examples

AndrisP 193 Posting Pro in Training

Its id who you try to insert as duplicate - result is no changes and supress error message

AndrisP 193 Posting Pro in Training

Actually it do not affect any changes - on duplicate update ... in your example supress error message. The same can be achieved with insert ignore into table ...

AndrisP 193 Posting Pro in Training

It's a very simple in single row:

string='India is a democracy'
print (' '.join([word for word in reversed(string.split(' '))]))
Aman_24 commented: thank u +0
AndrisP 193 Posting Pro in Training

You can add to CSS

.PaperApplication {
    visibility: hidden;
}

for set element with class PaperApplication hidden by default. After click radio button function change it to visible.

AndrisP 193 Posting Pro in Training

In JS months numbered from 0 to 11. Actually 11 is december. You can write simple function

function addMonths(d,n){
    var dt=new Date(d.getTime());
    dt.setMonth(dt.getMonth()+n);
    return dt;
}

and then e.g.

var d=new Date(); // current date
var d1=addMonths(d,1);
var d2=addMonths(d,2);
var d3=addMonths(d,3);

convert month number to 1-12

var n1=d1.getMonth()+1;
var n2=d2.getMonth()+1;
var n3=d3.getMonth()+1;
AndrisP 193 Posting Pro in Training

Please post human readable HTML

AndrisP 193 Posting Pro in Training

In your HTML code <table> not opened, table row <tr> not opened, invalid <input> tag without > - it should be something like

if($result->num_rows > 0){
    echo '<table>';
    while ($row6 = $result->fetch_assoc()){
        //table code//
        echo '<tr>';
        echo '<td><input type="checkbox"  name="check[]" value="'.$cato.'" /></td>';
        echo '</tr>';
    }
    echo '</table>';
}

PHP code $cat better use filtered variable

$cat = filter_input(
    INPUT_POST
    ,'check'
    ,FILTER_VALIDATE_INT
    ,FILTER_REQUIRE_ARRAY
);

other variables also filtered eg

$price = filter_input(INPUT_POST,'price',FILTER_SANITIZE_STRING);
$pickup_date = filter_input(INPUT_POST,'pickup_date',FILTER_SANITIZE_STRING);
...

Do not pass user input variables direct to SQL query - its a potential SQL injection risk! Use prepared statement instead - prepare, bind_param, execute - read manual MySQLi bind param or PDO bind param

jack98 commented: thanks for responding, really appreciate it. :) +0
AndrisP 193 Posting Pro in Training

Use backticks instead of apostrophes

`attendence` AS 'type'
,`in_address` AS 'address_in'
,`out_address` AS 'address_out'
AndrisP 193 Posting Pro in Training

Inputs should be inside form. Inputs with similar names should be pass as array.

<input type="checkbox" name="name[]" value="<?php echo $name;?>" /><?php echo $name;?>
AndrisP 193 Posting Pro in Training

Command enable/disable managed auto start of service on PC switch on or restart but for start/stop service must be used start/stop/restart command or you can check status using command status e.g.

systemctl status apache2
AndrisP 193 Posting Pro in Training

List of enabled/disabled srvices ~$ systemctl list-unit-files
Script for enable:

#!/bin/bash

for i in $*
do
    sudo systemctl enable $i
done

Call above script with passing multiple arguments or call below script with hardcoded services

#!/bin/bash

for i in eg_service_1 eg_service_2 eg_service_3
do
    sudo systemctl enable $i
done
AndrisP 193 Posting Pro in Training

HTML syntax is broken - line 103 <div, line 122 opened <div> is closed inside another table cell in line 144

AndrisP 193 Posting Pro in Training
AndrisP 193 Posting Pro in Training
$height=$_GET['height'];
$width=$_GET['width'];

Your code raise PHP error if variable not set - must be check if(isset($_GET['height'])){ $height=$_GET['height']; } or much better you can use filtered variables PHP - filter_input

$height = filter_input(INPUT_GET, 'height', FILTER_VALIDATE_INT);
$width = filter_input(INPUT_GET, 'width', FILTER_VALIDATE_INT);

Then set as session variables only if variable is not NULL

if($width !== NULL){
    $_SESSION['width'] = $width;
}
if($height !== NULL){
    $_SESSION['height'] = $height;
}

Otherwise your session variables always set to NULL if not set new values on each http request - in fact it does not work as a session variables

AndrisP 193 Posting Pro in Training

This looks good. Show PHP code where you try to set variables to global or session.

AndrisP 193 Posting Pro in Training

But word small not in your text file examples

AndrisP 193 Posting Pro in Training
  1. Uncripted password never store in to the database
  2. Use prepared statement instead of direct passing variables to SQL query
  3. Then write a question
AndrisP 193 Posting Pro in Training

Sorry on MS SQL server use datepart instead of extract

AndrisP 193 Posting Pro in Training
select min(`Date`), `Qty` from `tablename` group by extract(hour from `Date`);
AndrisP 193 Posting Pro in Training

Actually you can create multi level categories in single table if data structures are similar with references to self table . Second table contains references many-to-many e.g.

create table `categories`(
    `id` int primary key not null auto_increment
    ,`title` varchar(30) not null
    ,`description` varchar(300) not null
    ,`op_datetime` timestamp default current_timestamp on update current_timestamp
);
create table `cat_refs`(
    `id` int primary key not null auto_increment
    ,`cat_id` int not null
    ,`parent_id` int not null
    ,`op_datetime` timestamp default current_timestamp on update current_timestamp
);
alter table `categories` add constraint `unique_title` unique key(`title`);
alter table `cat_refs` add constraint `unique_ref` unique key(`cat_id`,`parent_id`);
alter table `cat_refs` add constraint `ref_to_cat`
    foreign key(`cat_id`) references `categories`(`id`);
alter table `cat_refs` add constraint `ref_to_parent`
    foreign key(`parent_id`) references `categories`(`id`);

drop procedure if exists `make_reference`;
drop procedure if exists `drop_reference`;
delimiter $$
create procedure `make_reference`(
    in `cat_title` varchar(30)
    ,in `parent_title` varchar(30)
)
begin
    declare `v_cat_id` int;
    declare `v_parent_id` int;
    select t.`id` into `v_cat_id` from `categories` t where t.`title` = `cat_title`;
    select t.`id` into `v_parent_id` from `categories` t where t.`title` = `parent_title`;
    if `v_cat_id` is not null and `v_parent_id` is not null then
        -- ignore witout errors if reference exists
        insert ignore into `cat_refs`(`cat_id`,`parent_id`) values (`v_cat_id`,`v_parent_id`);
    end if;
end $$

create procedure `drop_reference`(
    in `cat_title` varchar(30)
    ,in `parent_title` varchar(30)
)
begin
    declare `v_cat_id` int;
    declare `v_parent_id` int;
    select t.`id` into `v_cat_id` from `categories` t where t.`title` = `cat_title`;
    select t.`id` into `v_parent_id` from `categories` t where t.`title` = `parent_title`;
    delete from `cat_refs` where `cat_id` = `v_cat_id` and `parent_id` = `v_parent_id`;
end $$
delimiter ;

insert into …
AndrisP 193 Posting Pro in Training

Use

$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if($id !== NULL){
    ...
}

instead of lines 4,5,6, use prepared statement intead of direct pass variable (line 7) to prevent from SQL injection.
White space in GET parameter can be damage your variable <a href="newtestpage.php?id=<?php echo $post['C_ID'];?> #editEmployeeModal" class="edit" id ="<?php echo $post['C_ID'];?>" data-toggle="modal">
?id=<?php echo $post['C_ID'];?> #editEmployeeModal