Php Anket Yapımı

PHP ile IP Kontrollü Anket Yapımı

php ile anket yapma

 Bu dersimizde PHP ve MySQL kullanarak yapılmış anket uygulamasını ele alalım.
anket.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ANKETt</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="anketoyla.php">
  <table width="322" border="0" align="left">
    <tr>
      <td colspan="2" align="left">&nbsp;&nbsp;&nbsp;&nbsp;Sitemizi Nasıl Buldunuz?</td>
    </tr>
    <tr>
      <td width="48" align="center"><input type="radio" name="anket" id="radio2" value="5" /></td>
      <td width="264">Güzel</td>
    </tr>
    <tr>
      <td align="center"><input type="radio" name="anket" id="radio3" value="4" /></td>
      <td>İyi</td>
    </tr>
    <tr>
      <td align="center"><input type="radio" name="anket" id="radio4" value="3" /></td>
      <td>İdare Eder</td>
    </tr>
    <tr>
      <td align="center"><input type="radio" name="anket" id="radio" value="2" /></td>
      <td>Devam Et Daha Güzel Olacak :)</td>
    </tr>
    <tr>
      <td align="center"><input type="radio" name="anket" id="radio5" value="1" /></td>
      <td>Kötü</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label for="anket">
        <input type="submit" name="button" id="button" value="Gönder" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>

anketoyla.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
		$dbhost  = "localhost";   
$dbkullanici = "root";  
$dbsifre  = "root";
$dbadi = "anket_uygulamasi"; /* kendi veri tabanınızın adı ile değiştirin!*/
$baglan = mysql_connect($dbhost,$dbkullanici,$dbsifre);
mysql_select_db($dbadi,$baglan) or die ("veri tabanına bağlanamıyor");

	@$oy = $_POST['anket'];
	$ip = $_SERVER['REMOTE_ADDR'];
	$sor = mysql_query("select * from anket order by ip DESC LIMIT 0,10");
	while($cek = mysql_fetch_array($sor)){
		$ipp = $cek['ip'];
		}

		if($oy==""){
		echo"Lütfen Şıklardan Birini Seçiniz";
		}
		elseif($ip == @$ipp)
		{
			echo"Zaten Oy Kullanmışsınız.";	
		}else{
		$ekle = mysql_query("INSERT INTO anket(oy,ip) VALUES ('$oy','$ip')") or die("Ekleme Hatası");
		echo"Oy Kullandığınız için Teşekkür ederiz<br>
		<a href='anketsonuclar.php'>Sonucları Görmek İçin Tıklayınız...</a>";
		}

	?>
</body>
</html>

anketsonuclar.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
$dbhost  = "localhost";   
$dbkullanici = "root";  
$dbsifre  = "root";
$dbadi = "anket_uygulamasi"; /* kendi veri tabanınızın adı ile değiştirin!*/
$baglan = mysql_connect($dbhost,$dbkullanici,$dbsifre);
mysql_select_db($dbadi,$baglan) or die ("veri tabanına bağlanamıyor");

$sor = mysql_query("SELECT * FROM anket");
		while( $cek = mysql_fetch_array($sor)){
		$id = $cek['id'];
		$doy = $cek['oy'];
		}
		$oysayisi = mysql_num_rows($sor);

		$sorbes = mysql_query("SELECT * FROM anket where oy=5");{
		$besoy = mysql_num_rows($sorbes);
		$besoyyuzde =round((  ($besoy/ $oysayisi )*100),2);
		}
		$sordort = mysql_query("SELECT * FROM anket where oy=4");{
		$dortoy = mysql_num_rows($sordort);
		$dortoyyuzde = round(( ( $dortoy / $oysayisi )*100),2);
		}

		$soruc = mysql_query("SELECT * FROM anket where oy=3");{
		$ucoy = mysql_num_rows($soruc);
		$ucoyyuzde = round(( ( $ucoy /$oysayisi )*100),2);
		}

		$soriki = mysql_query("SELECT * FROM anket where oy=2");{
		$ikioy = mysql_num_rows($soriki);
		$ikioyyuzde =round(( ( $ikioy /$oysayisi )*100),2);
		}
		$sorbir = mysql_query("SELECT * FROM anket where oy=1");{
		$biroy = mysql_num_rows($sorbir);
		$biroyyuzde =round(( ($biroy  /$oysayisi )*100),2);
		}
		$toplam =$biroyyuzde + $ikioyyuzde  + $ucoyyuzde + $dortoyyuzde + $besoyyuzde;
		$biroyyuzde1=$biroyyuzde;
		$ikioyyuzde1=$ikioyyuzde;
		$ucoyyuzde1=$ucoyyuzde;
		$dortoyyuzde1=$dortoyyuzde;
		$besoyyuzde1=$besoyyuzde;
		echo"
<table width='642' border='0'>
  <tr>
    <td colspan='5' align='center'>Sonuçlar</td>
  </tr>
    <tr>
    <td colspan='3' align='center'>
    <td width='53'>Oy</td>
    <td width='106'> Yüzde</td>
  </tr>
  <tr>
    <td width='187'>Güzel</td>
    <td width='3' align='center'>:</td>
    <td width='259'><img src='images/formbar_kirmizi.jpg' height='17' width='$besoyyuzde1'></td>
    <td width='53'>$besoy</td>
    <td width='106'>%$besoyyuzde </td>
  </tr>
  <tr>
    <td>İyi</td>
    <td align='center'>:</td>
    <td><img src='images/formbar_sari.jpg'  height='17' width='$dortoyyuzde1' ></td>
    <td>$dortoy</td>
    <td>%$dortoyyuzde </td>
  </tr>
  <tr>
    <td>İdare Eder</td>
    <td align='center'>:</td>
    <td><img src='images/formbar_yesil.jpg'  height='17' width='$ucoyyuzde1'></td>
    <td>$ucoy</td>
    <td>%$ucoyyuzde </td>
  </tr>
  <tr>
    <td>Devam Et Daha Güzel Olacak</td>
    <td align='center'>:</td>
    <td><img src='images/formbar_turuncu.jpg'  height='17' width='$ikioyyuzde1' ></td>
    <td>$ikioy</td>
    <td>%$ikioyyuzde </td>
  </tr>
  <tr>
    <td>Kötü</td>
    <td align='center'>:</td>
    <td><img src='images/formbar_mavi.jpg'  height='17' width='$biroyyuzde1' ></td>
    <td>$biroy</td>
    <td>%$biroyyuzde </td>
  </tr>
  <tr>
    <td colspan='3' align='right'>Toplam Kullanılan Oy Sayısı&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td align='left'> $oysayisi</td>
    <td>%$toplam</td>
  </tr>
</table>"; ?>
</body>
</html>

sql

-- 
-- Tablo yapısı: `anket`
-- 

CREATE TABLE `anket` (
`id` int(11) NOT NULL auto_increment,
`oy` varchar(50) collate utf8_turkish_ci NOT NULL,
`ip` varchar(50) collate utf8_turkish_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=2 ;

-- 
-- Tablo döküm verisi `anket`
--

Cevapla

E-posta adresiniz yayınlanmayacak. Gerekli alanlar işaretlenmelidir *

*