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

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

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

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

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
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
  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

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

AndrisP 193 Posting Pro in Training

Directory is created? Add to line 5 "or die('Cannot create directory')" eg
mkdir($dirname) or die ("Cannot create directory");
check web server error log file. Probably permission denied.

AndrisP 193 Posting Pro in Training

Include database (line 9) should be outside of object User because in line 11 you define reference to db connection which is lost after comlete user construct

AndrisP 193 Posting Pro in Training

MySQLi method is shown in my first respond.
If you use bindParam() (PDO method - my second respond) $con should be PDO object.
Read http://php.net/manual/en/mysqli-stmt.bind-param.php and http://php.net/manual/en/pdostatement.bindparam.php

AndrisP 193 Posting Pro in Training

@Talib_1 this is (procedural) MySQLi method not PDO. The PDO would look something like this:

$stmt = $con->prepare("INSERT INTO table(id,s_id,date,time) VALUES (null,:s_id,:date,:time)");
$stmt->bindParam(':date', $date, PDO::PARAM_STR);
$stmt->bindParam(':time', $time, PDO::PARAM_STR);
foreach($s_id as $val){
    $stmt->bindParam(':s_id', $val, PDO::PARAM_INT);
    $stmt->execute();
}
Talib_1 commented: Thanks @AndrisP for your answer, I used this code appear(Fatal error: Call to a member function bindParam() on boolean) at line 2, how fix it? +0
AndrisP 193 Posting Pro in Training

Use prepared statement instead of direct insert to prevent from SQL injection!
Naming checkboxes with empty quadratic brackets e.g.

<input type="checkbox" name="s_id[]" value="1" />
<input type="checkbox" name="s_id[]" value="2" />
<input type="checkbox" name="s_id[]" value="3" />

PHP

$s_id=filter_input(INPUT_POST,'s_id',FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
$date=filter_input(INPUT_POST,'datee');
$time=filter_input(INPUT_POST,'time');

$stmt = mysqli_prepare($con, "INSERT INTO table(id,s_id,date,time) VALUES(null,?,?,?)");
mysqli_stmt_bind_param($stmt, "iss", $id,$d,$t);
$d=$date;
$t=$time;
foreach($s_id as $val){
    $id = $val;
    mysqli_stmt_execute($stmt);
}
Talib_1 commented: Thank you Mr. Andrisp for your answer, I used you code but appear some warning, I don't understand PDO codes can you use MySQLi codes instead PDO? +0
AndrisP 193 Posting Pro in Training

Why you do not use a switch? It would be more convenient here:

function kal(ta){
    var xy=ta,x1,x2,x3,x4;
    switch(xy){
        case 1: x1=0; x2=1; x3=1; x4=1; break;
        case 2: x1=1; x2=0; x3=1; x4=0; break;
        case 3: x1=0; x2=1; x3=0; x4=1; break;
        case 4: x1=1; x2=1; x3=1; x4=1; break;
        case 5: x1=0; x2=0; x3=1; x4=0; break;
        case 6: x1=0; x2=1; x3=1; x4=0; break;
        case 7: x1=1; x2=1; x3=1; x4=0; break;
        case 8: x1=1; x2=0; x3=1; x4=1; break;
        case 9: x1=1; x2=1; x3=0; x4=1; break;
        case 10: x1=0; x2=0; x3=1; x4=1; break;
        case 11: x1=1; x2=1; x3=0; x4=0; break;
        case 12: x1=0; x2=0; x3=0; x4=1; break;
        case 13: x1=0; x2=1; x3=0; x4=0; break;
        case 14: x1=1; x2=0; x3=0; x4=0; break;
        case 15: x1=1; x2=0; x3=0; x4=1; break;
        case 16: x1=0; x2=0; x3=0; x4=0; break;
    }
    this.xa = x1;
    this.xb = x2;
    this.xc = x3;
    this.xd = x4;
    return this;
}
AndrisP 193 Posting Pro in Training

Look to the console: "as" is not defined (line 29 and 95), function in parameter "ta" not used inside function.

AndrisP 193 Posting Pro in Training

It is not right answer - redundant white space after hiphens
right is: (\d{3}[-]){2}\d{5} (three digits with followed hiphens) {two times} and then five digits

AndrisP 193 Posting Pro in Training

I see you are using <input type="date" /> - do not need set date by jQuery, just add value (format YYYY-MM-DD), e.g. <input type="date" value="2018-09-24" />

pty commented: This is the best way by a mile +9
Jon_7 commented: Looks simple enough, but I can't get it to work +1
rproffitt commented: Today is that day. +15
AndrisP 193 Posting Pro in Training

Read tech spec abot your graphic card - max count of monitors, sum of max pixel-width and sum of max pixel-height

AndrisP 193 Posting Pro in Training

Your mistake is here caption='Harry' s SuperMart '

AndrisP 193 Posting Pro in Training

you can call destructor by set object to NULL e.g.

$stefan = new person();
$jimmy = new person();
$stefan->set_name('stefan');
$jimmy->set_name('jimmy');
echo "Stefan Full Name : ".$stefan->get_name();
echo "Jimmy Full Name : ".$jimmy->get_name();

$stefan = NULL;
$jimmy = NULL;
AndrisP 193 Posting Pro in Training

Also edit functions:

function set_name($new_name){
    $this->name = $new_name;
}

and

function get_name(){
    return $this->name;  
}
AndrisP 193 Posting Pro in Training

... or call constructor with param:

$stefan = new person('Stefan');
AndrisP 193 Posting Pro in Training

Edit __constructor to __construct and __destructor to __destruct.
If you define function with required argument then you cant initialize it without argument e.g.
Constructor with required argument:

function __construct($person_name){
    echo "Initialize class";
    $this->set_name($person_name);
}

Same contructor but argument is optional (set default value):

function __construct($person_name=NULL){
    echo "Initialize class";
    if($person_name !== NULL){
        $this->set_name($person_name);
    }
}