index.php
include("function.php");
$sinif = new islem();
?>
SB Admin 2 - Blank
$islem=$_GET["islem"];
switch ($islem):
case "ogrenciekle":
$sinif->ogrenciekle();
break;
case "ogrenciekleson":
$sinif->ogrenciekleson();
break;
case "ogrencilistesi":
$sinif->ogrencilistesi();
break;
case "ogrencilisteson":
$sinif->ogrencilisteson();
break;
endswitch;
?>
<script></script>
<script></script>
<script></script>
<script></script>
[/HTML]
function.php
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<script></script>
Document
<script>
$(document).ready(function(){
$("#ogrenci").click(function(){
//var ad =$("input[name=ad]").val();
// var numara = $("input[name=numara]").val();
$.ajax({
url:"index.php?islem=ogrenciekle",
type:"POST",
data: $('#form1').serialize(),
success:function () {
$("#result").fadeIn(1000).html("Öğrenci Ekleme Başarılı").fadeOut(3000);
}
})
})
$("#dersid").on('change',function () {
var deger = $(this).val();
$.ajax({
url:"index.php?islem=ogrencilisteson",
type:"POST",
data:{'dersid':deger},
success:function (cevap) {
}
})
})
})
</script>
try {
$db=new PDO("mysql:host=localhost;dbname=eevrak;charset=utf8",'root','12345678');
} catch (PDOException $e) {
echo $e->getMessage();
}
class islem {
function select($tablo){
global $db;
$s="select * from ".$tablo;
$ss=$db->prepare($s);
$ss->execute();
return $ss;
}
function ogrenciekle()
{
?>
}
function ogrenciekleson(){
$ad=htmlspecialchars($_POST["ad"]);
$numara=htmlspecialchars($_POST["numara"]);
$dersid=htmlspecialchars($_POST["dersid"]);
global $db;
$s="insert into aogrenciekle(ad,numara,dersid) values(:adi,:numarasi,:dersid)";
$ss=$db->prepare($s);
$ss->bindParam(":adi",$ad,PDO::PARAM_STR);
$ss->bindParam(":numarasi",$numara,PDO::PARAM_INT);
$ss->bindParam(":dersid",$dersid,PDO::PARAM_INT);
$ss->execute();
return "öğrenci eklenmiştir";
}
function ogrencilistesi()
{
global $db;
?>
if($_POST["dersid"]):
$dersid=$_POST["dersid"];
$s="select * from aogrenciekle where dersid=$dersid";
$ss=$db->prepare($s);
$ss->execute();
while($ok=$ss->fetch(PDO::FETCH_ASSOC)):
echo $ok["ad"]." ". $ok["numara"];
endwhile;
endif;
?>
}
function ogrencilisteson(){
if ($_POST["dersid"]):
$dersid = $_POST["dersid"];
$s = "select * from aogrenciekle where dersid=$dersid";
$ss = $db->prepare($s);
$ss->execute();
while ($ok = $ss->fetch(PDO::FETCH_ASSOC)):
echo $ok["ad"] . " " . $ok["numara"];
endwhile;
exit();
endif;
}
}
?>