1.Uue kasutaja loomine
2.
Uue tabeli loomine
1
2
3
4
5
6
|
create table puud( ID int primary key AUTO_INCREMENT, puunimi varchar (30), pilt text); insert into puud(puunimi, pilt) values ( 'Tamm' , 'Siin tuleb pilt' ); |
3.
conf.php
1
2
3
4
5
6
|
$serverName = "serveriNimi" ; $username = "nimi" ; $password = "Parool" ; $DBName = "ABNimi" ; $conn = new mysqli( $serverName , $username , $password , $DBName ); $conn ->set_charset( 'UTF8' ); |
4.Puud tabelid
require
(
"conf.php"
);
global
$conn
;
$kask
=
$conn
->prepare(
"SELECT puudID, nimi, link FROM puud where ID=?"
);
$kask->bind_param(
'i'
,
$_REQUEST
[
'id'
]);
$kask
->bind_result(
$ID
,
$puunimi
,
$pilt
);
$kask
->execute();
echo
"<strong>"
.
$nimi
.
"</strong><br>"
;
echo
"<img src='$link' alt='pilt' width='100%' height='100%'><br>"
;
echo
"<a href='$_SERVER[PHP_SELF]?delete=$puudID'>Kustuta</a> "
;
echo
"<a href='$_SERVER[PHP_SELF]?id="
.
$treesID
.
"&edit=$treesID'>Muuda</a>"
;
5.Puu pilt
require
(
"conf.php"
);
global
$conn
;
$order
=
$conn
->prepare(
"SELECT ID, puunimi, pilt FROM trees where treesID=?"
);
$order
->bind_param(
'i'
,
$_REQUEST
[
'id'
]);
$order
->bind_result(
$ID
,
$puunimi
,
$pilt
);
$order
->execute();
echo
"<strong>"
.
$puunimi
.
"</strong><br>"
;
echo
"<img src='$pilt' alt='pilt' width='100%' height='100%'><br>"
;
echo
"<a href='$_SERVER[PHP_SELF]?delete=$puudID'>Kustuta</a> "
;
echo
"<a href='$_SERVER[PHP_SELF]?id="
.
$puudID
.
"&edit=$puudID'>Muuda</a>"
;
6.Lisa nupp
1
2
3
4
5
6
7
8
9
10
11
|
if (isset( $_REQUEST [ 'lisa' ])){ ?> <form action= "" method= 'POST' > <input type= "hidden" name= "puuvorm" value= "yes" > <label for = "puunimi" >Nimi</label><br> <input type= "text" name= "puunimi" id= "puunimi" ><br> <label for = "pilt" >Pilt</label><br> <textarea name= "pilt" id= "pilt" ></textarea><br> <input type= "submit" value= "Lisa" id= "submit" > </form> <?php } ?> |
7. AB Lisamine
if
(isset(
$_REQUEST
[
'puuvorm'
])){
$kask
=
$yhendus
->prepare(
"insert into puud(nimi, pilt) values (?, ?)"
);
$kask
->bind_param(
"ss"
,
$_REQUEST
[
'puunimi'
],
$_REQUEST
[
'pilt'
]);
$kask
->execute()
;
}
8. Kustutamine
if
(isset(
$_REQUEST
[
'delete'
])){
$kask
=
$yhendus
->prepare(
"delete from puud where ID=?"
);
$kask
->bind_param(
"i"
,
$_REQUEST
[
'delete'
]);
$kask
->execute();
}
9.Muuda
1
2
3
4
5
6
7
8
9
10
11
12
|
if (isset( $_REQUEST [ 'edit' ])){ echo " <form action= '$_SERVER[PHP_SELF]' > <input type= 'hidden' name= 'change' value= '$puudID' > <h2>Puu andmete muutmine</h2> <input type= 'text' name= 'puunimi' value= '$puunimi' > Puunimi: <textarea name= 'pilt' value= '$pilt' ></textarea> <br> Pilt(peab olema pildilingi aadress) <input type= 'submit' value= 'muuda' > </form>"; |
10.AB muuda
if
(isset(
$_REQUEST
[
'muuda'
])){
$kask
=
$conn
->prepare(
"UPDATE puud SET nimi=?, link=? where treesID=?"
);
$kask
->bind_param(
"ssi"
,
$_REQUEST
[
'nimi'
],
$_REQUEST
[
'link'
],
$_REQUEST
[
'muuda'
]);
$kask
->execute();
}