PHP–Projek ROSES

1. config.php

<?php
//database configuration info
$db=mysqli_connect("localhost","root","abc123","roses");
if($db==false){
echo "DB connect error: ";
echo mysqli_connect_error($db);
}else{
//echo "Database connected";
}

?>


 


2: senarairekod.php


image



<?php
//paparan semua rekod
include "config.php";
?>
<html>
<head>
<title>Roses: Laporan</title>
</head>
<body>
Senarai semua rekod dalam jadual Daftar<br>
<?php
//sql command to fectch all records
$sql="SELECT id , namapertubuhan , alamat ,
poskod , negeri FROM daftar"
;
//send sql command to db server
$rs=mysqli_query($db, $sql);
//display sql error
if($rs==false){
echo mysqli_error($db);
}
//identify number of records
$bilrekod=mysqli_num_rows($rs);
if($bilrekod==0){
echo "Tiada rekod diperolehi";
}
else{//rekod ada, boleh papar
?>
<table width="90%" border="1">
<tr align="center">
<td>id</td>
<td>Nama pertubuhan</td>
<td>Alamat</td>
<td>Poskod</td>
<td>Negeri</td>
</tr>
<?php
while($rekod=mysqli_fetch_array($rs)){
?>
<tr>
<td><?=$rekod['id']?></td>
<td><?=$rekod['namapertubuhan']?></td>
<td><?=$rekod['alamat']?></td>
<td><?=$rekod['poskod']?></td>
<td><?=$rekod['negeri']?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>





3. carian.php


image


<?php
//paparan semua rekod
include "config.php";
?>
<html>
<head>
<title>Roses: Carian</title>
</head>
<body>
Cari nama Pertubuhan<br>

<form action="" method="get" name="formsearch">
Enter a name <input name="txtsearch" type="text">
<input name="btnsearch" type="submit" value="Cari">
</form>
<?php
$carian=$_GET['txtsearch'];
echo "Carian untuk: $carian <br>";
//sql command to fetch all records
$sql="SELECT id , namapertubuhan , alamat ,
poskod , negeri FROM daftar
WHERE namapertubuhan LIKE '%$carian%' "
;
//send sql command to db server
$rs=mysqli_query($db, $sql);
//display sql error
if($rs==false){
echo mysqli_error($db);
}
//identify number of records
$bilrekod=mysqli_num_rows($rs);
if($bilrekod==0){
echo "Tiada rekod diperolehi";
}
else{//rekod ada, boleh papar
?>
<table width="90%" border="1">
<tr align="center">
<td>id</td>
<td>Nama pertubuhan</td>
<td>Alamat</td>
<td>Poskod</td>
<td>Negeri</td>
</tr>
<?php
while($rekod=mysqli_fetch_array($rs)){
?>
<tr>
<td><?=$rekod['id']?></td>
<td><?=$rekod['namapertubuhan']?></td>
<td><?=$rekod['alamat']?></td>
<td><?=$rekod['poskod']?></td>
<td><?=$rekod['negeri']?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>





4. carian-nama-tahun.php


image


<?php
//paparan semua rekod
include "config.php";
?>
<html>
<head>
<title>Roses: Carian</title>
</head>
<body>
Cari nama Pertubuhan<br>

<form action="" method="get" name="formsearch">
Nama pertubuhan <input name="txtsearch" type="text"
value="<?php echo $_GET['txtsearch'] ?>">
Tahun didaftar <input name="txttahun" type="text"
value="<?php echo $_GET['txttahun'] ?>"
maxlength=4>
<input name="btnsearch" type="submit" value="Cari">
</form>
<?php
$carian=$_GET['txtsearch'];
$tahun=$_GET['txttahun'];
echo "Carian untuk pertubuhan: $carian <br>";
echo "Tahun didaftar: $tahun <br>";
//sql command to fetch all records
$sql="SELECT id , namapertubuhan , alamat ,
poskod , negeri, masadaftar FROM daftar
WHERE namapertubuhan LIKE '%$carian%'
AND year(masadaftar)='$tahun'"
;
//send sql command to db server
$rs=mysqli_query($db, $sql);
//display sql error
if($rs==false){
echo mysqli_error($db);
}
//identify number of records
$bilrekod=mysqli_num_rows($rs);
if($bilrekod==0){
echo "Tiada rekod diperolehi";
}
else{//rekod ada, boleh papar
?>
<table width="90%" border="1">
<tr align="center">
<td>id</td>
<td>Nama pertubuhan</td>
<td>Alamat</td>
<td>Poskod</td>
<td>Negeri</td>
<td>Tarikh daftar</td>
</tr>
<?php
while($rekod=mysqli_fetch_array($rs)){
?>
<tr>
<td><?=$rekod['id']?></td>
<td><?=$rekod['namapertubuhan']?></td>
<td><?=$rekod['alamat']?></td>
<td><?=$rekod['poskod']?></td>
<td><?=$rekod['negeri']?></td>
<td><?=$rekod['masadaftar']?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>




 

 

5. insert.php

 

image

<?php
//paparan semua rekod
include "config.php";
?>
<html>
<head>
<title>Roses: Masuk rekod baru</title>
</head>
<body>
Cari nama Pertubuhan<br>

<form action="" method="get" name="forminsert">
Nama pertubuhan <input name="txtnama" type="text"><br>
Alamat <input name="txtalamat" type="text"><br>
Poskod <input name="txtposkod" type="text" maxlength=5><br>
Negeri
<select name="txtnegeri">
<?php
$rsn=mysqli_query($db, "SELECT * FROM negeri");
while($recn=mysqli_fetch_array($rsn)){
echo "<option value=".$recn['kodnegeri'].">".
$recn['keterangan']."</option>";
}
?>
</select>
<br>
No Telefon <input name="txttelefon" type="text"><br>
Emel <input name="txtemel" type="text"><br>
Nama Setiausaha <input name="txtnamasu" type="text"><br>
No KP Setiausaha <input name="txticsu" type="text"><br>

<input name="btninsert" type="submit" value="Simpan">
</form>
<?php
$nama=$_GET["txtnama"];
$alamat=$_GET["txtalamat"];
$poskod=$_GET["txtposkod"];
$negeri=$_GET["txtnegeri"];
$telefon=$_GET["txttelefon"];
$emel=$_GET["txtemel"];
$namasu=$_GET["txtnamasu"];
$icsu=$_GET["txticsu"];
if ($nama!=null){//pastikan user dah masukkan data
//sql utk masukkan rekod baru dlm db
$sql="INSERT INTO daftar
values
('','$nama','$alamat','$poskod','$negeri',
'$telefon','$emel','$namasu','$icsu','')"
;
$rs=mysqli_query($db, $sql);
if($rs==false){
echo "Error in sql:".mysqli_error($db);
echo "Full sql: $sql";
}else{
echo "Nama pertubuhan: $nama<br>";
echo "Alamat: $alamat, $poskod, $negeri<br>";
echo "Rekod berjaya disimpan<br>";
}
}//if not null
?>
</body>
</html>





6. listedit.php

 

image

<?php
//paparan semua rekod
include "config.php";
?>
<html>
<head>
<title>Roses: Senarai utk Edit</title>
</head>
<body>
Cari nama Pertubuhan<br>

<form action="" method="get" name="formsearch">
Enter a name <input name="txtsearch" type="text">
<input name="btnsearch" type="submit" value="Cari">
</form>
<?php
$carian=$_GET['txtsearch'];
echo "Carian untuk: $carian <br>";
//sql command to fetch all records
$sql="SELECT id , namapertubuhan , alamat ,
poskod , negeri FROM daftar
WHERE namapertubuhan LIKE '%$carian%' "
;
//send sql command to db server
$rs=mysqli_query($db, $sql);
//display sql error
if($rs==false){
echo mysqli_error($db);
}
//identify number of records
$bilrekod=mysqli_num_rows($rs);
if($bilrekod==0){
echo "Tiada rekod diperolehi";
}
else{//rekod ada, boleh papar
?>
<table width="90%" border="1">
<tr align="center">
<td> </td>
<td>id</td>
<td>Nama pertubuhan</td>
<td>Alamat</td>
<td>Poskod</td>
<td>Negeri</td>
</tr>
<?php
while($rekod=mysqli_fetch_array($rs)){
$id=$rekod['id'];
?>
<tr>
<td><a href="edit.php?id=<?php echo $id?>">
edit</a></td>
<td><a href="hapus.php?id=<?php echo $id?>">
hapus</a></td>
<td><?php echo $rekod['id']?></td>
<td><?php echo $rekod['namapertubuhan']?></td>
<td><?php echo $rekod['alamat']?></td>
<td><?php echo $rekod['poskod']?></td>
<td><?php echo $rekod['negeri']?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>




 

 

7. edit.php

image


<?php
//paparan semua rekod
include "config.php";
$id=$_GET['id'];
$sqle="SELECT * FROM daftar WHERE id='$id'";
$rse=mysqli_query($db, $sqle);
$re=mysqli_fetch_array($rse);
$nama=$re['namapertubuhan'];
$alamat=$re['alamat'];
$poskod=$re['poskod'];
$negeri=$re['negeri'];
$telefon=$re['telefon'];
$email=$re['email'];
$namasu=$re['namasu'];
$icsu=$re['icsu'];
?>
<html>
<head>
<title>Roses: Edit rekod lama</title>
</head>
<body>
Edit Pertubuhan<br>

<form action="simpan.php" method="get" name="forminsert">
ID <input name="txtid" type="text"
value="<?php echo $id ?>"><br>
Nama pertubuhan <input name="txtnama" type="text"
value="<?php echo $nama ?>"><br>
Alamat <input name="txtalamat" type="text"
value="<?php echo $alamat ?>"><br>
Poskod <input name="txtposkod" type="text" maxlength=5
value="<?php echo $poskod ?>"><br>
Negeri <?php echo $negeri ?>
<select name="txtnegeri">
<?php
$rsn=mysqli_query($db, "SELECT * FROM negeri");
while($recn=mysqli_fetch_array($rsn)){
if($recn['kodnegeri']==$negeri){
echo "<option value=".$recn['kodnegeri']." selected >".
$recn['keterangan']."</option>\n";
}else{
echo "<option value=".$recn['kodnegeri']." >".
$recn['keterangan']."</option>\n";
}
}
?>
</select>
<br>
No Telefon <input name="txttelefon" type="text"
value="<?php echo $telefon ?>"><br>
Emel <input name="txtemel" type="text"
value="<?php echo $email ?>"><br>
Nama Setiausaha <input name="txtnamasu" type="text"
value="<?php echo $namasu ?>"><br>
No KP Setiausaha <input name="txticsu" type="text"
value="<?php echo $icsu ?>"><br>

<input name="btninsert" type="submit" value="Simpan">
</form>

</body>
</html>







0. Database


-- phpMyAdmin SQL Dump
-- version 2.11.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 13, 2011 at 03:58 AM
-- Server version: 5.0.45
-- PHP Version: 5.2.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `roses`
--
CREATE DATABASE `roses` DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci;
USE `roses`;

-- --------------------------------------------------------

--
-- Table structure for table `daftar`
--
CREATE TABLE `daftar` (
`id` int(11) NOT NULL auto_increment,
`namapertubuhan` varchar(100) collate latin1_general_ci NOT NULL,
`alamat` varchar(100) collate latin1_general_ci NOT NULL,
`poskod` varchar(5) collate latin1_general_ci NOT NULL,
`negeri` varchar(2) collate latin1_general_ci NOT NULL,
`telefon` varchar(15) collate latin1_general_ci NOT NULL,
`email` varchar(100) collate latin1_general_ci NOT NULL,
`namasu` varchar(100) collate latin1_general_ci NOT NULL,
`icsu` varchar(14) collate latin1_general_ci NOT NULL,
`masadaftar` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=11 ;

--
-- Dumping data for table `daftar`
--
INSERT INTO `daftar` (`id`, `namapertubuhan`, `alamat`, `poskod`, `negeri`, `telefon`, `email`, `namasu`, `icsu`, `masadaftar`) VALUES
(1, 'Persatuan Kerabat Abd Rahman', 'Parit Sulong, Batu Pahat', '83500', '01', '0129034614', 'khirulnizam@gmail.com', 'Khirulnizam Abd Rahman', '760818017303', '2011-10-12 10:39:14'),
(2, 'Persatuan Pembangun Laman Web', 'Bangi', '43600', '10', '0389254251', 'webdev@gmail.com', 'Ali Mamat', '770801032872', '2011-10-12 10:39:14'),
(3, 'Rumah Amal Nilai', 'Taman Semarak, Nilai', '71700', '05', '0172131234', 'amalnilai@gmail.com', 'Faridah Ali', '870102142341', '2011-10-12 10:40:58'),
(10, 'Pertubuhan Web Se-Malaysia', 'Parit Jawa, Muar', '83000', '01', '', '', '', '', '2011-10-12 16:46:45');

-- --------------------------------------------------------

--
-- Table structure for table `negeri`
--
CREATE TABLE `negeri` (
`kodnegeri` varchar(2) collate latin1_general_ci NOT NULL,
`keterangan` varchar(50) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`kodnegeri`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

--
-- Dumping data for table `negeri`
--
INSERT INTO `negeri` (`kodnegeri`, `keterangan`) VALUES
('01', 'Johor'),
('02', 'Kedah'),
('03', 'Kelantan'),
('04', 'Melaka'),
('05', 'Negeri Sembilan'),
('06', 'Pahang'),
('07', 'Pulau Pinang'),
('08', 'Perak'),
('09', 'Perlis'),
('10', 'Selangor'),
('11', 'Terengganu'),
('12', 'Sabah'),
('13', 'Sarawak'),
('14', 'Wilayah Persekutuan (Kuala Lumpur)'),
('15', 'Wilayah Persekutuan (Labuan)'),
('16', 'Wilayah Persekutuan (Putrajaya)');


 

Popular Posts