Title: Konektivitas PHP - MySQL
1 Konektivitas PHP - MySQL PHP - 2 Ir. H.
Sumijan, M.Sc
2Koneksi PHP - MySQL
- Untuk melakukan koneksi PHP dengan MySQL
digunakan perintah mysql_connect() -gt skrip PHP. - Syntak mysql_connect(hostname,username,passw
ord)
3Koneksi PHP - MySQL
- Setelah terkoneksi, pilihlah database.
- Bila database yang diinginkan belum tersedia,
buatlah databasenya. - Buatlah tabel, dengan struktur datanya.
4Koneksi PHP - MySQL
lt? //Membuat database MySQL nama_db
dbbola" buat_db "create database
nama_db" sambung mysql_connect("localhost","
root","") if(sambung) echo "Koneksi
Berhasil" else echo "Koneksi Gagal" q_db
mysql_query(buat_db) if(q_db) echo "ltbrgt
Database nama_db berhasil dibuat" else echo
"ltbrgt Database nama_db gagal dibuat" ?gt
Koneksi Database
5Koneksi PHP - MySQL
lt? //Membuat tabel MySQL nama_db
dbbola" nama_tbl "Liga" sambung
mysql_connect("localhost","root","") if(sambung)
echo "Koneksi Berhasil" else echo
"Koneksi Gagal" mysql_select_db(nama_db,sambu
ng) or die("Koneksi ke nama_db
gagal") buat_tbl "create table nama_tbl
(kode char(5) not null, negara char(10) not null,
champion int)" qtbl mysql_query(buat_tbl,sa
mbung) if(qtbl) echo "ltbrgtTabelnama_tbl
berhasil dibuat" else echo "ltbrgtTabel
nama_tbl gagal dibuat" ?gt
Membuat Tabel
6Koneksi PHP - MySQL
- Membuat Form sebagai input pada sistem database.
- Input disimpan dalam satu tabel tertentu.
- Pada attribut action ditentukan file yang
memiliki skrip PHP untuk menyimpan input ke tabel
pada database.
7Koneksi PHP - MySQL
lthtmlgt ltheadgt lttitlegtFormulir Input
Ligalt/titlegt ltmeta authorSoegt lt/headgt ltbodygt lth1
gtMasukkan Data Ligalt/h1gt ltform methodpost
actionsimpan.phpgt lttablegt lttrgt
lttdgtKodelt/tdgt lttdgtltinput typetext namekode
size20gtlt/tdgt lt/trgt lttrgt lttdgtNegaralt/tdgt
lttdgtltinput typetext namenegara size20gtlt/tdgt
lt/trgt
Skrip Form Input
8Koneksi PHP - MySQL
lttrgt lttdgtChampionlt/tdgt lttdgtltinput typetext
namechampion size20gtlt/tdgt lt/trgt lttrgt lttd
aligncentergtltinput typesubmit namesubmit
valueSimpangtlt/tdgt lttd aligncentergtltinput
typereset namereset valueUlangigtlt/tdgt lt/trgt
lt/tablegt lt/formgt lt/bodygt lt/htmlgt
9Koneksi PHP - MySQL
10Koneksi PHP - MySQL
- Untuk menyimpan input ke tabel MySQL, terlebih
dahulu input dibaca sesuai metode yang digunakan. - Untuk menyimpan ke database digunakan perintah
- hasil mysql_query(SQL Statement)
11Koneksi PHP - MySQL
lt? sambung mysql_connect("localhost","root","")
mysql_select_db(dbbola,sambung) or
die("Koneksi ke dbbola gagal") ?gt lthtmlgt ltheadgt
lttitlegtSimpan Ligalt/titlegt ltmeta
authorSoegt lt/headgt ltbodygt lth1gtData
Baranglt/h1gt lt? kode _POSTkode negara
_POSTnegara champion _POSTchampion ?gt
Skrip Simpan Data
12Koneksi PHP - MySQL
lt? q_simpan "insert into Liga values('kode'
,'negara','champion')" hasil
mysql_query(q_simpan,sambung) if(hasil) echo
"Data tersimpan ltbrgt" echo "Kode
".kode."ltbrgt" echo "Negara
".negara."ltbrgt" echo "Champion
".champion."ltbrgt" else echo "Data gagal
disimpan" ?gt ltform methodpost
actionfrm_input_Liga.phpgt ltinput typesubmit
valueKembaligt lt/formgt lt/bodygt lt/htmlgt
Skrip Simpan Data
13Koneksi PHP - MySQL
14Koneksi PHP - MySQL
lt? tampil "select from Liga" q_buat
mysql_query(tampil,sambung) ?gt lttable
border1gt lttrgt lttdgtKodelt/tdgt lttdgtNegaralt/tdgt
lttdgtChampionlt/tdgt lt/trgt lt? while(row
mysql_fetch_row(q_buat)) echo ("lttr
aligncentergtlttdgtrow0lt/tdgt") echo
("lttdgtrow1lt/tdgt") echo ("lttdgtrow2lt/tdgtlt/trgt
") ?gt lt/tablegt lt? //ltform methodpost
actionedit.phpgtltinput typesubmit valueEdit
nameeditgtlt/formgt //ltform methodpost
actiontambah.phpgtltinput typesubmit valueTambah
nametambahgtlt/formgt ?gt
Skrip Menampilkan Data
15Koneksi PHP - MySQL
16Koneksi PHP - MySQL
- Form Pencarian
- Buat Input dengan type radio untuk memilih field
pencarian. - Buat Input dengan type text sebagai kata kunci
pencarian. - Buat tombol Cari, Input -gt type Submit
17Koneksi PHP - MySQL
ltHTMLgt ltHEADgt lttitlegtCari Databaselt/titlegt lt/HE
ADgt ltBODYgt lth1gtSearching Liga untuk database
MySQLlt/h1gt ltform action"hasilsearch.php"
method"post"gt ltselect name"kolom"gt ltoption
value"kode"gtKodelt/optiongt ltoption
value"negara"gtNegaralt/optiongt lt/selectgt Masukkan
kata yang anda cari ltinput type "text" type
"text" name"cari"gt ltinput type "submit"
value"cari" gt lt/formgt lt/BODYgt lt/HTMLgt
Form - Search
18Koneksi PHP - MySQL
19Koneksi PHP - MySQL
lt? kolom_POST'kolom' cari_POST'cari'
connmysql_connect("localhost","root","")
mysql_select_db(dbbola", conn)
hasilmysql_query("select from Liga where
kolom like 'cari'", conn)
jumlahmysql_num_rows(hasil) echo "ltbrgt"
echo "Ditemukan jumlah" echo "ltbrgt"
while(barismysql_fetch_array(hasil))
echo "Kode " echo baris0 echo
"ltbrgt" echo "Negara " echo baris1
echo "ltbrgt" echo "Champion " echo
baris2 ?gt
Skrip Search
20Koneksi PHP - MySQL
21Contoh Kasus - 1
CREATE TABLE employee (id int(12) NOT NULL
auto_increment,name varchar(255) NOT
NULL,address varchar(255) NOT NULL,city
varchar(255) NOT NULL,PRIMARY KEY (id))
ENGINEMyISAM DEFAULT CHARSETlatin1
AUTO_INCREMENT7 INSERT INTO employee (id,
name, address, city) VALUES (1, 'Soe', '10
street dane', 'Pune'),(2, 'Debie', '12907A 53 St
NW', 'Mumbai'),(3, 'Atika', '3rd Floor, 888 Fort
Street', 'Noida'),(4, 'Widya', 'Sir Frederick W
Haultain Building 9811 109 ST NW', 'London'),(5,
'Danny', 'Suite 303, 13220 St. Albert Trail',
'Sydney'),(6, 'Yettri', '9700 Jasper Avenue',
'Perth')
Nama Database dbwork Script Table mahasiswa
22Nama File Config.php
lt? sDbHost 'localhost' sDbName
dbwork' sDbUser 'root' sDbPwd
'' dbConn mysql_connect (sDbHost, sDbUser,
sDbPwd) or die ('MySQL connect failed. ' .
mysql_error()) mysql_select_db(sDbName,dbConn)
or die('Cannot select database. ' .
mysql_error()) ?gt
23Nama File View.php
lthtmlgt ltheadgt lttitlegtView Recordslt/titlegt lt/headgt
ltlink href"style.css" rel"stylesheet"
type"text/css"gt ltbodygt lt?php include('config.php'
) result mysql_query("SELECT FROM
employee") or die(mysql_error()) echo "lttable
border'1' cellpadding'10'gt" echo
"lttrgt ltthgtltfont color'FFFF00'gtIdlt/fontgtlt/thgt ltth
gtltfont color'FFFF00'gtNamelt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtAddresslt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtCitylt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtEditlt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtDeletelt/fontgtlt/thgt lt/trgt"
24Lanjutan Nama File View.php
while(row mysql_fetch_array( result )) echo
"lttrgt" echo 'lttdgtltbgtltfont color"663300"gt' .
row'id' . 'lt/fontgtlt/bgtlt/tdgt' echo
'lttdgtltbgtltfont color"663300"gt' . row'name' .
'lt/fontgtlt/bgtlt/tdgt' echo 'lttdgtltbgtltfont
color"663300"gt' . row'address' .
'lt/fontgtlt/bgtlt/tdgt' echo 'lttdgtltbgtltfont
color"663300"gt' . row'city' .
'lt/fontgtlt/bgtlt/tdgt' echo 'lttdgtltbgtltfont
color"663300"gtlta href"edit.php?id' .
row'id' . '"gtEditlt/agtlt/fontgtlt/bgtlt/tdgt' echo
'lttdgtltbgtltfont color"663300"gtlta
href"delete.php?id' . row'id' .
'"gtDeletelt/agtlt/fontgtlt/bgtlt/tdgt' echo
"lt/trgt" echo "lt/tablegt" ?gt ltpgtlta
href"insert.php"gtInsert new recordlt/agtlt/pgt lt/body
gt lt/htmlgt
25Nama File Insert.php
lt?php function valid(name, address,city,
error) ?gt lthtmlgt ltheadgt lttitlegtInsert
Recordslt/titlegt lt/headgt ltlink href"style.css"
rel"stylesheet" type"text/css"gt ltbodygt lt?php if
(error ! '') echo 'ltdiv style"padding4px
border1px solid red colorred"gt'.error.'lt/divgt
' ?gt ltform action"" method"post"gt lttable
border"1"gt lttrgt lttd colspan"2"gtltbgtltfont
color'Red'gtInsert Records lt/fontgtlt/bgtlt/tdgt lt/trgt
26Lanjutan Nama File Insert.php
lttrgt lttd width"179"gtltbgtltfont color'663300'gtName
ltemgtlt/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"name" value"lt?php echo name
?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtAddressltemgtlt
/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"address" value"lt?php echo
address ?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtCityltemgtlt/em
gtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput type"text"
name"city" value"lt?php echo city ?gt"
/gt lt/labelgtlt/tdgt lt/trgt
27Lanjutan Nama File Insert.php
lttr align"Right"gt lttd colspan"2"gtltlabelgt ltinput
type"submit" name"submit" value"Insert
Records"gt lt/labelgtlt/tdgt lt/trgt lt/tablegt lt/formgt lt/b
odygt lt/htmlgt lt?php include('config.php') if
(isset(_POST'submit')) name
mysql_real_escape_string(htmlspecialchars(_POST'
name')) address mysql_real_escape_string(html
specialchars(_POST'address')) city
mysql_real_escape_string(htmlspecialchars(_POST'
city')) if (name '' address ''
city '')
28Lanjutan Nama File Insert.php
error 'Please enter the details!' valid(name,
address, city,error) else mysql_query("IN
SERT employee SET name'name',
address'address', city'city'") or
die(mysql_error()) header("Location
view.php") else valid('','','','') ?gt
29Nama File Edit.php
lt?php function valid(id, name, address,city,
error) ?gt lthtmlgt ltheadgt lttitlegtEdit
Recordslt/titlegt lt/headgt ltlink href"style.css"
rel"stylesheet" type"text/css"gt ltbodygt lt?php if
(error ! '') echo 'ltdiv style"padding4px
border1px solid red colorred"gt'.error.'lt/divgt
' ?gt ltform action"" method"post"gt ltinput
type"hidden" name"id" value"lt?php echo id
?gt"/gt lttable border"1"gt lttrgt lttd
colspan"2"gtltbgtltfont color'Red'gtEdit Records
lt/fontgtlt/bgtlt/tdgt lt/trgt
30Lanjutan Nama File Edit.php
lttrgt lttd width"179"gtltbgtltfont color'663300'gtName
ltemgtlt/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"name" value"lt?php echo name
?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtAddressltemgtlt
/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"address" value"lt?php echo
address ?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtCityltemgtlt/em
gtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput type"text"
name"city" value"lt?php echo city ?gt"
/gt lt/labelgtlt/tdgt lt/trgt lttr align"Right"gt lttd
colspan"2"gtltlabelgt ltinput type"submit"
name"submit" value"Edit Records"gt lt/labelgtlt/tdgt
lt/trgt lt/tablegt lt/formgt lt/bodygt lt/htmlgt lt?php
31Lanjutan Nama File Edit.php
include('config.php') if (isset(_POST'submit'
)) if (is_numeric(_POST'id')) id
_POST'id' name mysql_real_escape_string(htm
lspecialchars(_POST'name')) address
mysql_real_escape_string(htmlspecialchars(_POST'
address')) city mysql_real_escape_string(html
specialchars(_POST'city')) if (name ''
address '' city '') error 'ERROR
Please fill in all required fields!' valid(id,
name, address,city, error) else mysql_que
ry("UPDATE employee SET name'name',
address'address' ,city'city' WHERE
id'id'") or die(mysql_error()) header("Location
view.php") else echo 'Error!'
32Lanjutan Nama File Edit.php
else if (isset(_GET'id')
is_numeric(_GET'id') _GET'id' gt 0) id
_GET'id' result mysql_query("SELECT
FROM employee WHERE idid") or
die(mysql_error()) row mysql_fetch_array(resu
lt) if(row) name row'name' address
row'address' city row'city' valid(id,
name, address,city,'') else echo "No
results!" else echo 'Error!' ?gt
33Nama File Delete.php
lt?php include('config.php') if
(isset(_GET'id') is_numeric(_GET'id'))
id _GET'id' result mysql_query("DELETE
FROM employee WHERE idid") or
die(mysql_error()) header("Location
view.php") else header("Location
view.php") ?gt
34Nama File style.css
body color2e6ab1 table
border-collapse collapse th
background-color 2e6ab1 padding-left
14px padding-right 8px border 1px solid
969BA5 text-alignleft colorffffff
td background-color F0F0F0 padding-left
8px padding-right 8px padding-top
2px padding-bottom 2px border 1px solid
969BA5 color2e6ab1 Input, select
color2e6ab1
35Contoh Kasus - 2
CREATE TABLE mhs ( NIM varchar(16) NOT NULL
default '', Nama varchar(145) NOT NULL default
'', TglLahir date NOT NULL default
'0000-00-00', Kelas varchar(15) NOT NULL
default '', Jrs char(3) NOT NULL default '',
PRIMARY KEY (NIM), KEY NIM (NIM) )
TYPEMyISAM INSERT INTO mhs VALUES
('091011152620001', 'Pradani', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620002', 'Atika', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620003', 'Danny', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620004', 'Debie', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620005', 'Cintya', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620006', 'Asep', '1966-07-10', 'SK-4',
'262') INSERT INTO mhs VALUES ('091011152620007',
'Joko', '1966-07-10', 'SK-4', '262') INSERT
INTO mhs VALUES ('091011152620008', 'Acong',
'1966-07-10', 'SK-4', '262') INSERT INTO mhs
VALUES ('091011152620009', 'Ucok', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620010', 'Baba', '1966-07-10', 'SK-4',
'262') INSERT INTO mhs VALUES ('091011152620011',
'Khan', '1966-07-10', 'SK-4', '262') INSERT
INTO mhs VALUES ('091011152620012', 'Nere',
'1966-07-10', 'SK-4', '262') INSERT INTO mhs
VALUES ('091011152620013', 'Sania', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620014', 'Riani', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620015', 'Ryan', '1966-07-10', 'SK-4',
'262') INSERT INTO mhs VALUES ('091011152620016',
'Wilujeng', '1966-07-10', 'SK-4', '262')
Nama Database dbmhs Script Table mahasiswa
36Nama File BrowseMhs.php
?gtphp ltfont color"FF0000"gt lt? conmysql_connec
t("localhost","root","") dbmysql_select_db("dbm
hs") sql"Select from mhs" hasilmysql_query
(sql) while (rowmysql_fetch_array(hasil))
echo "rowNIM-rowNama-rowTglLahir-
rowKelas-rowJrs" echo "lta
href'editmhs.php?NIMrowNIM'gt Edit lt/agt "
echo "lta href'deletemhs.php?NIMrowNIM'gt
Deletelt/agt lthrgt" ?gt
37Nama File editmhs.php
lt?php nim_REQUESTNIM conmysql_connect("lo
calhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mhs where NIM'nim'
" hasilmysql_query(sql) rowmysql_fetch_arra
y(hasil) namarowNama tgllahirrowTglLah
ir kelasrowKelas jrsrowJrs ?gt
38Lanjutan Nama File editmhs.php
ltfont color"FF0000"gt ltform action""
method"GET"gt NIM ltinput type"text" name"NIM"
value"lt? echo nim ?gt "gtltbrgt Nama ltinput
type"text" name"Nama" value"lt? echo nama ?gt
"gtltbrgt Tanggal Lahir ltinput type"text"
name"TglLahir" value"lt? echo tgllahir ?gt
"gtltbrgt Kelas ltinput type"text" name"Kelas"
value"lt? echo kelas ?gt "gtltbrgt Jurusan ltinput
type"text" name"Jrs" value"lt? echo jrs ?gt
"gtltbrgt ltinput type"submit" name"simpan"
value"Update"gt ltinput type"reset" name"batal"
value"Cancel"gt lt/formgt
39Lanjutan Nama File editmhs.php
lt? if (_REQUESTsimpan'Update')
echo "Proses Updating..!" nim_REQUESTNIM
nama_REQUESTNama tgllahir_REQUESTTg
lLahirkelas_REQUESTKelas
jrs_REQUESTJrs sql"update mhs set
NIM'nim', Nama'nama', TglLahir'tgllahir',
Kelas'kelas', Jrs'jrs' where NIM'nim'
" hasilmysql_query(sql) echo
"Berhasil di Update..!" ?gt lthrgtlta
href"ListMhs.php"gtBacklt/agt
40Nama File deletemhs.php
lt?php nim_REQUESTNIM conmysql_connect("loc
alhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mhs where NIM'nim'
" hasilmysql_query(sql) rowmysql_fetch_arra
y(hasil) namarowNama tgllahirrowTglLah
ir kelasrowKelas jrsrowJrs ?gt
41Lanjutan Nama File deletemhs.php
ltfont " color"FF0000"gt ltform action""
method"GET"gt NIM ltinput type"text" name"NIM"
value"lt? echo nim ?gt "gtltbrgt Nama ltinput
type"text" name"Nama" value"lt? echo nama ?gt
"gtltbrgt Tanggal Lahir ltinput type"text"
name"TglLahir" value"lt? echo tgllahir ?gt
"gtltbrgt Kelas ltinput type"text" name"Kelas"
value"lt? echo kelas ?gt "gtltbrgt Jurusan ltinput
type"text" name"Jrs" value"lt? echo jrs ?gt
"gtltbrgt ltinput type"submit" name"simpan"
value"Delete"gt ltinput type"reset" name"batal"
value"Cancel"gt lt/formgt
42Lanjutan Nama File deletemhs.php
lt? if (_REQUESTsimpan'Delete')
echo "Proses Deleting..!" sql" delete
from mhs where NIM'nim' "
hasilmysql_query(sql) echo "Berhasil
di Hapus..!" ?gt lta href"ListMhs.php"gtBacklt
/agt
43Nama File menu.php
ltp align"left"gt ltbr/gt lt?php echo "lta
href\"addmhs.php\"gtAdd Mhslt/agtltbr/gt" echo "lta
href\"browsemhs.php\"gtBrowse Mhslt/agtltbr/gt"
echo "lta href\"Listmhs.php\"gtList
Mhslt/agtltbr/gt" echo "lta href\"FormLogin.php\"gtEx
itlt/agtltbr/gt" echo "ltbr/gt" echo "ltbr/gt" ?gt
lt/pgt
44Nama File addmhs.php
lt?php conmysql_connect("localhost","root","")
dbmysql_select_db("dbmhs") ?gt ltfont
color"FF0000"gt ltform action""
method"GET"gt NIM ltinput type"text"
name"NIM"gtltbrgt Nama ltinput type"text"
name"Nama"gtltbrgt Tanggal Lahir ltinput type"text"
name"TglLahir"gtltbrgt Kelas ltinput type"text"
name"Kelas"gtltbrgt Jurusan ltinput type"text"
name"Jrs"gtltbrgt ltinput type"submit"
name"simpan" value"Add"gt ltinput type"reset"
name"batal" value"Cancel"gt lt/formgt
lt? if (_REQUESTsimpan'Add') echo
"Proses Adding..!" nim_REQUESTNIMnama
_REQUESTNama tgllahir_REQUESTTglLahir
kelas_REQUESTKelas jrs_REQUESTJrs
sql"Insert into mhs values ('nim', 'nama',
'tgllahir', 'kelas', 'jrs')"
hasilmysql_query(sql) echo "Berhasil
di Disimpan..!" ?gt lthrgtlta hrefmenu.php"gtBac
klt/agt
45Listmhs.php
ltfont color"FF0000"gt lt? conmysql_connect("loca
lhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mhs" hasilmysql_query(sql)
while (rowmysql_fetch_array(hasil)) echo
"rowNIM-rowNama-rowTglLahir-
rowKelas-rowJrslthrgt" ?gt lta
hrefmenu.phpgtBacklt/agt
46 CREATE TABLE mtk ( KodeMK varchar(10) NOT NULL
default '', NamaMK varchar(145) NOT NULL
default '', SKS int, KodeJrs char(3) NOT NULL
default '', PRIMARY KEY (KodeMK), KEY
KodeMK (KodeMK) ) TYPEMyISAM INSERT INTO mtk
VALUES ('KKKI12001', 'Pancasila', '2',
'263') INSERT INTO mtk VALUES ('KKKI12002',
'Agama', '2', '263') INSERT INTO mtk VALUES
('KKKI12003', 'Bahasa Indonesia', '2',
'263') INSERT INTO mtk VALUES ('KKKI12004',
'Kewarganegaraan', '2', '263') INSERT INTO mtk
VALUES ('KKKI12005', 'Etika Profesi', '2',
'263')
Script Table matakuliah
47CREATE TABLE ambilmk ( nim varchar(16) NOT NULL
default '', kodeMK varchar(10) NOT NULL default
'', nilai char(2) defalt NULL, PRIMARY KEY
(nim,kodeMK) ) TYPEMyISAM INSERT INTO
ambilmk VALUES ('091011152620003', 'KKKI12001',
'A') INSERT INTO ambilmk VALUES
('091011152620003', 'KKKI12002', 'A') INSERT
INTO ambilmk VALUES ('091011152620003',
'KKKI12003', 'B') INSERT INTO ambilmk VALUES
('091011152620003', 'KKKI12004', 'A') INSERT
INTO ambilmk VALUES ('091011152620003',
'KKKI12005', 'C') INSERT INTO ambilmk VALUES
('091011152620016', 'KKKI12002', 'A') INSERT
INTO ambilmk VALUES ('091011152620016',
'KKKI12003', 'B') INSERT INTO ambilmk VALUES
('091011152620016', 'KKKI12005', 'A')
Script Table ambilmk
48ltfont color"FF0000"gt lt? conmysql_connect("loca
lhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mtk" hasilmysql_query(sql)
while (rowmysql_fetch_array(hasil)) echo
"rowKodeMK-rowNamaMK-rowSKS-rowKodeJrs
" echo "lta href'editmtk.php?KodeMKrowKodeMK
'gt Edit lt/agt " echo "lta href'deletemtk.php?
KodeMKrowKodeMK'gt Deletelt/agt lthrgt" ?gt
49Nama File FormInputkrs.php
lt?php mysql_connect("localhost", "root",
"") mysql_select_db("dbmhs") sql"Select
from mhs" hasilmysql_query(sql) ?gt ltfont
size"" color"FF0000"gt ltform method"post"
action"simpan.php"gt Nomor BP ltselect
name"nim"gt lt? while (rowmysql_fetch_array(hasi
l)) echo "ltoption valuerowNIMgtrowNIMlt/opt
iongt" echo "lt/selectgtltbrgtltbrgt" query
"SELECT FROM mtk" hasil mysql_query(query)
no 1 while (data mysql_fetch_array(hasil)
) echo "ltinput type'checkbox'
value'".data'KodeMK'."' name'mk".no."' /gt
".data'KodeMK'.' - '.data'NamaMK'."ltbr
/gt" no ?gt ltbrgt ltinput type"hidden"
name"jumMK" value"lt?php echo no-1 ?gt"
/gt ltinput type"submit" name"submit"
value"Ambil" /gt lt/formgt
50Nama File simpan.php
lt?php mysql_connect("localhost", "root",
"") mysql_select_db("dbmhs") nim
_REQUEST'nim' jumMK _POST'jumMK' for(i
1 i lt jumMK i) mk
_POST'mk'.i if (!empty(mk))
query "INSERT INTO ambilMK VALUES('nim',
'mk', '-')" mysql_query(query)
echo "Terimakasih sudah memilih
matakuliah" ?gt
51FormNilai.php
lt?php header('Content-typetext/vnd.wap.wml') ech
o('lt?xml version"1.0"?gt') echo('lt!DOCTYPE wml
PUBLIC "-//WAPFORUM// DTD WML 1.1/EN"gt') mysql_co
nnect("localhost", "root", "") mysql_select_db("d
bmhs") sql"Select from mtk" hasilmysql_que
ry(sql) ?gt ltcard id"KRS" title"Form
Nilai"gt ltfont size"" color"FF0000"gt ltform
method"post" action"simpan1.php"gt Nomor BP
ltselect name"kodemk"gt lt? while
(rowmysql_fetch_array(hasil)) echo "ltoption
valuerowKodeMKgtrowKodeMKlt/optiongt" echo
"lt/selectgtltbrgtltbrgt" query "SELECT FROM
ambilmk, mhs, mtk where ambilmk.nimmhs.NIM and
ambilmk.kodeMKmtk.KodeMK order by
mhs.NIM" hasil mysql_query(query) no
1 lt/cardgt lt/wmlgt
52while (data mysql_fetch_array(hasil))
echo "ltselect name'nl".no."'gt" echo
"ltoption value'A'gtAlt/optiongt" echo "ltoption
value'B'gtBlt/optiongt" echo "ltoption
value'C'gtClt/optiongt" echo "ltoption
value'D'gtDlt/optiongt" echo "ltoption
value'E'gtElt/optiongt" echo "ltoption
value'TL'gtTLlt/optiongt" echo "ltinput
type'hidden' value'".data'nim'."'
name'nim".no."' /gt" echo "ltinput
type'hidden' value'".data'kodeMK'."'
name'mk".no."' /gt ".data'nim'.' -
'.data'NamaMK'.' - '.data'kodeMK'."ltbr/gt"
no ?gt lt/selectgt ltbrgt ltinput type"hidden"
name"jumMK" value"lt?php echo no-1 ?gt"
/gt ltinput type"submit" name"submit"
value"Ambil" /gt lt/formgt
53simpan1.php
lt? header('Content-typetext/vnd.wap.wml') echo('
lt?xml version"1.0"?gt') echo('lt!DOCTYPE wml
PUBLIC "-//WAPFORUM// DTD WML 1.1/EN"gt') mysql_co
nnect("localhost", "root", "") mysql_select_db("d
bmhs") jumMK _POST'jumMK' for(i 1 i
lt jumMK i) mk _REQUEST'mk'.i
nim _REQUEST'nim'.i nl
_REQUEST'nl'.i if (!empty(mk))
query "update ambilMK set nilai'nl'
where nim'nim' and kodeMK'mk'"
mysql_query(query) echo "Terimakasih
sudah memilih matakuliah" ?gt
54Nama File ListNilai.php
ltbgtltbiggtDAFTAR NILAI MAHASISWA lt? conmysql_conne
ct("localhost","root","") dbmysql_select_db("db
mhs") sql"SELECT mhs.NIM, Nama, mtk.KodeMK,
NamaMK, SKS, nilai FROM ambilmk, mhs, mtk where
ambilmk.nimmhs.NIM and ambilmk.kodeMKmtk.KodeMK
order by mhs.NIM" hasilmysql_query(sql) nim
'091011152620001' bb0tbb0tsks0nu0 ech
o "ltfont size-5 colorFF0000gtltbrgtlthrgt" while
(rowmysql_fetch_array(hasil))
55Lanjutan Nama File ListNilai.php
nu if (nim!rowNIM)
if (nugt1)
echo "ltbgtIndek Prestasi " echo
number_format(ip,2,',','.')
echo "ltbrgtlthrgt"
bb0tbb0tsks0nu0
if (rownilai'A') mutu4
elseif (rownilai'B') mutu3
elseif (rownilai'C') mutu2 elseif
(rownilai'D') mutu1 elseif
(rownilai'E') mutu0 elseif
(rownilai'TL) mutu'0'
56Lanjutan Nama File ListNilai.php
bbmuturowSKS tskstsksrowSKS
tbbtbbbb if (tbbgt0)
iptbb/tsks echo "rowNIM-rowNama-row
KodeMK-rowNamaMK-rowSKS-rownilai-mutu-
bblthrgt" nimrowNIM echo "ltbgtIndek
Prestasi " echo number_format(ip,2,',','.') ec
ho "lthrgt" ?gt
57Nama File .php
58Nama File .php
59Nama File .php
60Nama File .php
61Nama File .php
62Nama File .php
63Nama File .php
64Nama File .php
65Nama File .php
66Nama File .php
67Nama File .php
68Nama File .php
69Nama File .php
70Nama File .php
71Nama File .php
72Nama File .php
73Nama File .php
74Nama File .php
75Nama File .php
76Nama File .php
77Nama File .php
78Nama File .php
79Nama File .php
80Nama File .php
81Nama File .php
82Nama File .php
83Nama File .php
84Nama File .php
85Nama File .php
86Nama File .php
87Nama File .php
88Nama File .php
89Nama File .php
90Nama File .php
91Nama File .php
92Nama File .php
93Nama File .php
94Nama File .php
95Nama File .php
96Nama File .php
97Nama File .php
98Nama File .php
99Nama File .php
100Nama File .php
101Nama File .php
102Nama File .php