PHP Form Örnekleri

sdkbyrm

webmasterfrm
Üyelik Tarihi
23 Aralık 2020
Mesajlar
813
Beğeniler
1
Ticaret: 0 / 0 / 0
PHP Örnekleri konusunda daha önceden yaptığımız örneklerde PHP kodlarının temel kullanımıyla ilgili örnekler oluşturmuştuk. Genellikle değerleri kod içerisinde bir değişkene aktararak gerçekleştirdik. Bu yazımızda yine basit örnekler fakat diğer konudan farklı olarak kullanıcı etkileşimi olan yani kullanıcıdan veriler alarak gerçekleştireceğimiz örnekler oluşturacağız. Bu sayfadaki örnekler sürekli güncellenecektir.


Örnek : Kullanıcı adını girip butona tıkladığında ekranda “Merhaba kullanıcı” mesajı veren PHP Form Örneği.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="deneme.php" method="post">
Adınız:<br>
<input type="text" name="txtAd"><br>
<input type="submit" name="btn" value="GÖNDER">
</form>
<div>
<?php
if(isset($_POST["btn"])){ //isset() ile hesapla butonuna basılıp basılmadığını kontrol ediyoruz.
$ad=$_POST["txtAd"];
echo("Merhaba ".$ad);
}
?>
</div>

</body>
</html>




Örnek : Kullanıcı adını girip butona tıkladığında ekranda “Merhaba kullanıcı” mesajı veren eğeer isim girmemişse Adınızı Girin mesajını ekranda yazdıran PHP Form Örneği.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="deneme.php" method="post">
Adınız:<br>
<input type="text" name="txtAd"><br>
<input type="submit" name="btn" value="GÖNDER">
</form>
<div>
<?php
if(isset($_POST["btn"])){ //isset() ile hesapla butonuna basılıp basılmadığını kontrol ediyoruz.
$ad=$_POST["txtAd"];
if($ad!=""){
echo("Merhaba ".$ad);
}
else{
echo("Adınızı Girin.");
}

}
?>
</div>

</body>
</html>






Örnek: PHP ile kullanıcının girdiği iki sayıyı toplayan ve sonucu yazdıran örnek.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="deneme.php" method="post">
Sayı 1:<br>
<input type="text" name="txtSayi1"><br>
Sayı 2:<br>
<input type="text" name="txtSayi2"><br>
<input type="submit" name="btn" value="TOPLA">
</form>
<div>
<?php
if(isset($_POST["btn"])){ //isset() ile hesapla butonuna basılıp basılmadığını kontrol ediyoruz.
$s1=$_POST["txtSayi1"];
$s2=$_POST["txtSayi2"];
$toplam=$s1+$s2;
echo($s1." + ".$s2." = ".$toplam);
}
?>
</div>

</body>
</html>




Örnek: index.php sayfasında text kutusuna veri girip Buttona basıldığında verileri test.php sayfasına gönderme örneği.

index.php içeriği



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.yazilimkodlama.com</title>
</head>

<body>
<form action="test.php" method="post">
<input type="text" name="mesaj"><br>
<input type="submit" name="gonder">
</form>
</body>
</html>
test.php içeriği


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.yazilimkodlama.com</title>
</head>

<body>
<?php
if(isset($_POST["gonder"])){
$mesaj=$_POST["mesaj"];
echo("Merhaba ".$mesaj);
}
?>
</body>
</html>
Ekran Çıktısı:







Örnek: Kullanıcının girdiği 2 sayıyı toplayan, çıkaran, çarpan ve bölen, daha sonra sonucu yazdıran PHP Örneği.

index.php



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="test.php" method="post">
Sayı 1<br>
<input type="text" name="txtSayi1"><br>
Sayı 2<br>
<input type="text" name="txtSayi2"><br>
<input type="submit" name="btnHesap">
</form>
</body>
</html>


test.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_POST["btnHesap"])){
$s1=$_POST["txtSayi1"];
$s2=$_POST["txtSayi2"];
$toplam=$s1+$s2;
$fark=$s1-$s2;
$carpim=$s1*$s2;
$bolum=$s1/$s2;
}
?>
<h1>TOPLAM : <?php echo($toplam); ?> </h1>
<h1>FARK : <?php echo($fark); ?> </h1>
<h1>ÇARPIM : <?php echo($carpim); ?> </h1>
<h1>BÖLÜM : <?php echo($bolum); ?> </h1>
</body>
</html>


Ekran Çıktısı:






Örnek: Kullanıcı tarafından girilen iki sayının toplamını yazdıran PHP kodunu yazınız.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.yazilimbilisim.net - PHP Örnekleri</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>
<div class="container">

<h1 class="bg-primary">
<?php
if(isset($_POST["kontrol"]))//kontrol adında bir form nesnesi var mı kontrolü yapılıyor
{
echo $_POST["sayi1"]+$_POST["sayi2"];
}
?>
</h1>
<hr>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<div class="form-group">
<label for="sayi1">Sayı 1</label>
<input type="text" class="form-control" name="sayi1">
</div>
<div class="form-group">
<label for="sayi2">Sayı 2</label>
<input type="text" class="form-control" name="sayi2">
</div>
<button type="submit" name="kontrol" class="btn btn-default" >Kontrol Et</button>
</form>
</div>
</body>
</html>
php-form-%C3%B6rnekleri.png




Örnek : Kullanıcı tarafından girilen Vize ve Final Notuna göre geçme Kalma durumunu ekrana yazdıran program


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.yazilimbilisim.net - PHP Örnekleri</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>
<div class="container">
<?php
if(isset($_POST["kontrol"]))//kontrol adında bir form nesnesi var mı kontrolü yapılıyor
{
$vize=$_POST["vize"];
$final=$_POST["final"];
$sonuc=$vize*0.4 + $final*0.6;
if($sonuc >= 60 && $final >= 60)
{
echo "<h1 class='text-info'>$sonuc ,GEÇTİ</h1>";
}
else
{
echo "<h1 class='text-danger'>$sonuc ,KALDI</h1>";
}
}
?>
<hr>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<div class="form-group">
<label for="vize">Vize Notu:</label>
<input type="text" class="form-control" name="vize">
</div>
<div class="form-group">
<label for="final">Final Notu:</label>
<input type="text" class="form-control" name="final">
</div>
<button type="submit" name="kontrol" class="btn btn-default" >Kontrol Et</button>
</form>
</div>
</body>
</html>


php-form-%C3%B6rnekleri-2.png




Örnek: Kullanıcının girdiği sayıya kadar olan sayıları yazdıran PHP kodunu yazınız.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.yazilimbilisim.net - PHP Örnekleri</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>
<div class="container">
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<div class="form-group">
<label for="sayi">Sayı Girin:</label>
<input type="text" class="form-control" name="sayi">
</div>
<button type="submit" name="kontrol" class="btn btn-default" >ÇALIŞTIR</button>
</form>
</div>
<!-- PHP KODLARI -->
<div class="container">
<?php
if(isset($_POST["kontrol"]))//kontrol adında bir form nesnesi var mı kontrolü yapılıyor
{

$sayi=$_POST["sayi"];
for($i=0;$i<=$sayi;$i++)
{
echo "<button class='btn btn-info'>$i</button> ";
}
}
?>
</div>
</body>
</html>
Screenshot_1.png




 
Üst