Sintaknya adalah
<html>
<head>
<title>Quick Direct!!!</title>
</head>
<body bgcolor="white">
<center>Free Add Links </center>
<hr>
<!--Begin Directory-->
br><li><a href="http://webit.ml.org/scripts/">WEB-IT CGI Scripts Archive</a>
<hr>
<center><a href="http://webit.ml.org/scripts/">WEB-IT CGI Scripts
Archive</a></center>
</body>
</html>
<center><h1>Database Doctor</h1>
This page should probably be somewhere password protected...either that or change the
name and hide it...
<table border=0>
<tr><td>
New Users Name</td><td><INPUT type=text name="new_user" size=20></td></tr>
<tr><td>
Password</td><td><INPUT type="text" name="new_pass" size=20></td></tr></table>
<p>
<INPUT type="Submit" name="pass" Value=" Set the New Users Login ">
</FORM>
</BODY>
</HTML>
Membuat Form Pemesanan Barang
<! Sample Order Form Template >
<! Comments start with a bracket and exclamation point >
<! Please read all the comments in the form before making any >
<! Modifications to the form. And backup the form before making >
<! any changes so you will always have a working copy!! >
<! Modifications are not difficult, but when working with html >
<! strange things happen when you delete tags that should not >
<! be deleted. So please follow the instructions carefully. >
<! Change Merchant's Order Form to your business name below. >
<HTML>
<HEAD>
<TITLE>Order Form</TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080>
<CENTER>
<TABLE WIDTH="600">
<TR>
<TD ALIGN="CENTER"><FONT FACE="Arial" size=5><B>Merchant's Order
Form</FONT></TD>
</TR>
</TABLE><BR>
<! This block of code gives instructions for your customers who >
<! want to pay by check or money order. Replace the Merchant Name >
<! with your company name and replace the address lines 1 and 2. >
<! If you do not accept checks or money orders you can delete the >
<! whole block of code. >
<! Modify the action statement in the form tag below >
<! to point to eaccountant.cgi on your system. Do not >
<! forget to leave ?process_order on the end. >
<! Change your@email.com to your email address. >
<! Change the subject of the email. >
<! Do NOT remove the HIDDEN form field. >
<! This is a nested table for the grey section of the form >
<TABLE WIDTH="100%">
<TR>
<TD WIDTH="494" COLSPAN="2" ALIGN="CENTER" BGCOLOR="#FCCA03">
<FONT FACE="Arial" COLOR="#FF0000"><B>CustomerInformation</B></FONT>
</TD>
</TR>
<! A blank row >
<TR>
<TD><BR><BR>
</TD></TR>
<! Row for first name with 2 columns, one for the description of >
<! the item, the other for the input box. >
<! You shouldn't have to modify anything in this section. >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-1">First
Name:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="fname" SIZE="30"></P></TD>
</TR>
<! Row for last name with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-1">Last
Name:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="name" SIZE="30"></P></TD>
</TR>
<! Row for address with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">Address:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="address1" SIZE="30"></P></TD>
</TR>
<! Row for 2nd address box with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">Address:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="address2" SIZE="30"></P></TD>
</TR>
<! Row for city with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">City:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="city" SIZE="30"></P></TD>
</TR>
<! Row for state with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">State/Province:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="state" SIZE="30"></P></TD>
</TR>
<! Row for country with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">Country:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="country" SIZE="30"></P></TD>
</TR>
<! Row for zip with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-1">Zip
Code:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="zip" SIZE="30"></P></TD>
</TR>
<! Row for phone number with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">Telephone:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="phone" SIZE="30"></P></TD>
</TR>
<! Row for email address with 2 columns >
<TR>
<TD WIDTH="178" ALIGN="RIGHT"><FONT FACE="Arial" SIZE="-
1">Email:</FONT></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="email" SIZE="30"></P></TD>
</TR>
<! Blank row >
<TR><TD><BR><BR></TD></TR>
<TR>
<TD WIDTH="700" COLSPAN="2" ALIGN="CENTER" BGCOLOR="#FCCA03">
<FONT FACE="Arial" COLOR="#FF0000"><B>Order
Information</B></FONT></TD>
</TR>
<TR><TD><BR><BR></TD></TR>
<TR>
<TD WIDTH="700" COLSPAN="2"><CENTER>
<! Nested table for the item radio boxes and quantity input boxes. >
<! To modify an entry replace the name=" " with the name of your >
<! product. Make sure it matches a product you have entered into >
<! e-Accountant exactly. Also change the value=" " to the same >
<! as the name=" ", and add your description of the product. >
<! If you do not collect sales tax you can delete this >
<! block of code. If you collect sales tax just modify the state >
<! and the tax amount. >
<! If you do not ship products or do not charge for shipping you >
<! can delete this block of code. If you charge for shipping, modify >
<! the shipping methods and prices in the two sections below. >
<! Remember that your shipping methods must match what you have >
<! entered into e-Accountant exactly. >
</CENTER></TABLE></B>
<TR><TD><BR><BR></TD></TR>
<! Start of credit card information code. Modify the values as needed. >
<! We have blocked off the code for each type of card so you can >
<! delete code if necessary. >
<TR>
<TD WIDTH="700" COLSPAN="2" ALIGN="CENTER"
BGCOLOR="#FCCA03"><FONT FACE="Arial" COLOR="#FF0000"><B>Credit
Card Information</B></FONT></TD>
</TR>
<TR><TD><BR><BR></TD></TR>
<TR>
<TD WIDTH="178"><FONT FACE="Arial" SIZE="-1">Please choose
one:</FONT></TD>
<TD WIDTH="316">
<TABLE WIDTH="100%">
<! Start Visa >
<TR>
<TD WIDTH="28">
<P><INPUT TYPE="RADIO" NAME="cardtype" VALUE="Visa"
CHECKED="CHECKED"></P></TD>
<TD WIDTH="46"><FONT FACE="Arial" SIZE="-1">Visa</FONT></TD>
<TD WIDTH="25">
<! Start Mastercard >
<P><INPUT TYPE="RADIO" NAME="cardtype"
VALUE="Mastercard"></P></TD>
<TD WIDTH="105"><FONT FACE="Arial" SIZE="-1">Master
Card</FONT></TD>
<TD WIDTH="26">
<! Start Amex >
<P><INPUT TYPE="RADIO" NAME="cardtype" VALUE="American
Express"></P></TD>
<TD WIDTH="76"><FONT FACE="Arial" SIZE="-1">Amex</FONT></TD>
<! End Amex >
</TR>
</TABLE></TD>
</TR>
<TR>
<TD WIDTH="178"><FONT FACE="Arial" SIZE="-1">Credit Card
Number:</FONT></TD>
<TD WIDTH="316"><FONT FACE="Arial" SIZE="-1"> Please leave a space
between grouped numbers</FONT></TD>
</TR>
<TR>
<TD WIDTH="178"></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="cardnumber" SIZE="40"></P></TD>
</TR>
<TR>
<TD WIDTH="178"><FONT FACE="Arial" SIZE="-1">Exp.
Date:</FONT></TD>
<TD WIDTH="316"><FONT FACE="Arial" SIZE="-1">Example 0599 = May
1999</FONT>.</TD>
</TR>
<TR>
<TD WIDTH="178"></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="exp"></P></TD>
</TR>
<TR>
<TD WIDTH="178"><FONT FACE="Arial" SIZE="-
1">Cardholder:</FONT></TD>
<TD WIDTH="316"><FONT FACE="Arial" SIZE="-1">Exact name on the
Credit Card:</FONT></TD>
</TR>
<TR>
<TD WIDTH="178"></TD>
<TD WIDTH="316">
<P><INPUT TYPE="TEXT" NAME="fullname" SIZE="30"></P></TD>
</TR>
<TR>
<TD WIDTH="178"></TD>
<TD WIDTH="316">
<BR><BR>
<P><CENTER><INPUT TYPE="SUBMIT" NAME="Submit1"
VALUE="Submit">
<INPUT TYPE="RESET" NAME="Reset1"></P></CENTER></TD>
</TR>
<! Start display of your business information. Fill in your company >
<! name, address and phone number here. >
<TR>
<TD WIDTH="178"></TD>
<TD WIDTH="316"><HR WIDTH=450>
<CENTER><FONT FACE="Arial" SIZE="-1"><B>Merchant Name<BR>
<B>Address 1<BR>
<B>Address 2<BR>
<B>Phone Number</FONT></CENTER></TD>
</TR>
</TABLE></FORM></TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
Prosesor.PHP
<?php
# FILE: processors.php
# DATE: 11/27/02
# AUTHOR: ShaunC "Bulworth"
# PROJECT: CC Processor Gateway Interface
# COPYRIGHT: PHPLabs.Com
# ----
# Description: This file contains the function used to post
# transactions 2Checkout.
################################################################
# You MUST set the following variable before using the script #
################################################################
$merchant2cuser = "test";
################################################################
# End of configuration - No need to edit below this line #
################################################################
$target = "https://www.2checkout.com/cgi-bin/sbuyers/cartpurchase.2c?";
$amount = sprintf("%.02f", $amount);
if(!$invoice)
$invoice = sprintf("%06d", rand(111111, 999999));
$params = "sid=$merchant2cuser&total=$amount&cart_order_id=$invoice";
header("Location: $target$params");
?>
Menangkap Variabel Post
database
create database db_gb ;
use db_gb;
create table guestbook (id int unsigned not null primary key auto_increment, nama
varchar(50) not null, email varchar(100) not null, pesan text not null);
file koneksi.php
<?php
$host="localhost"; $uname="root"; $pass=""; $db="db_gb";
$koneksi=mysql_connect($host,$uname,$pass);
mysql_select_db($db,$koneksi);
?>
file lihatgb.php
<?php
$queryGb = mysql_query("select * from guestbook");
$jmlGb = mysql_num_rows($queryGb);
if($jmlGb==0)
{
echo"Data buku tamu masih kosong";
}
else
{
$queryTampil=mysql_query("select * from guestbook order by id desc");
echo"<p>DATA BUKU TAMU<p>";
while($dataGb=mysql_fetch_row($queryTampil))
{
echo"<b>$dataGb[1]</b><br>";
echo"".wordwrap($dataGb[3],85,"<br>",1)." ";
echo"<hr width=50% align=left>";
}
}
?>
file gb.php
<?php
include'koneksi.php';
include'lihatgb.php';
PHP Looping
PHP Looping
1. While Loops
while (expression)
{
code to
execute;
}
script-------------
<?php
$num = 1;
print 'Done.';
?>
script-------------
menghasilkan:
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
Number is 6
Number is 7
Number is 8
Number is 9
Number is 10
Done.
2. For Loops
syntax untuk For Loops adalah
script-------------
<?php
for ($num = 1; $num <= 10; $num++) {
print "Number is $num<br />\n";
}
?>
script-------------
menghasilkan:
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
Number is 6
Number is 7
Number is 8
Number is 9
Number is 10
script-------------
<?php
$counter = -3;
?>
script-------------
menghasilkan:
100/-3
100/-2
100/-1
Stopping to avoid division by zero.
*dia akan loop sampai fungsi if dan karena ada script break, maka proses akan berhenti
*script ini suatu saat akan berguna "Trust me"
4. continue Statements
script-------------
<?php
$counter =- 3;
?>
script-------------
menghasilkan:
100/-3
100/-2
100/-1
Skipping to avoid zero.
100/1
100/2
100/3
100/4
100/5
100/6
100/7
100/8
100/9
*dia akan loop sampai fungsi if dan karena ada script continue, maka proses akan
berhenti mengganti angka 0 menjadi
Skipping to avoid zero, lalu looping akan di lanjutkan kembali
- include()
- include_once()
- require()
Fugnsi di atas berguna untuk menggabungkan file PHP atau bukan PHP kedalam file
PHP
+++ include()
sebagai contoh
head.php
-----
<?php
echo "selamat datang di website ku<br>";
?>
-----
body.php
-----
<?php
include 'head.php';
echo "<br>Ini adalah contant atau isi dari website ku<br>";
?>
-----
hasilnya:
selamat datang di website ku
Ini adalah contant atau isi dari website ku
+++ include_once()
"include_once()" berfungsi untuk membatasi fungsi include cuma untuk satu kali saja
contoh jika tidak menggunakan "include_once()":
body.php
-----
<?php
include 'head.php';
include 'head.php';
include 'head.php';
echo "<br>Ini adalah content atau isi dari website ku<br>";
?>
-----
hasilnya:
selamat datang di website ku
selamat datang di website ku
selamat datang di website ku
Ini adalah content atau isi dari website ku
+++ require()
fungsi ini tidak jauh beda dengan fungsi "include()" alias sama,
jadi kita loncati saja fungsi ini
body.php
------
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/head.php');
?>
------
body.php
------
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/head.php');
?>
------
Untuk melihat dimana posisi file php anda, anda bisa gunakan:
<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>
Ok kita mulai
- Define
di sini saya akan jelaskan sedikit tentang define:
define mirip dengan, "string":
---------------
<?php
define("HELLO", "Hello world!");
echo HELLO;
?>
---------------
Nanti hasilnya: "Hello world."
Contoh Penerapan:
<?php
if ($user == b_scorpio)
{
echo "user anda b_scorpio";
}
?>
Contoh Penerapan:
<?php
if ($user == b_scorpio)
{
echo "user anda b_scorpio";
}
else
{
echo "anda bukan b_scorpio";
}
?>
else
{
echo "anda tidak bisa login";
}
?>
// artibut file
$fileName = 'sample.zip';
$mimeType = 'application/zip';
readfile($fileName);
else {
header("location: redirect");
}
?>
1. File Koneksi.php
<?php
$host="localhost"; $uname="root"; $pass="phii"; $db="db_artikel";
$koneksi=mysql_connect($host,$uname,$pass);
mysql_select_db($db,$koneksi);
?>
2. File fungsi.php
<?php
function cuplikArtikel($konten,$url)
{
$maxKata=20; //max kata dalam cuplikan artikel --> silahkan diganti sesuai kebutuhan
$pecahArtikel=explode(' ',$konten); //pecah artikel menjadi array of string
if(count($pecahArtikel) > $maxKata)
{
$cuplik='';
for($a=0;$a<$maxKata;$a++)
{
$cuplik.=$pecahArtikel[$a]." " ;
}
echo"$cuplik . . . .<br><a href=$url>Selengkapnya>> </a>";
}
else
{
echo $konten;
}
}?
>
3. File artikel_cuplik.php
<?php
include 'koneksi.php';
include 'fungsi.php';
if(isset($_GET['act']) && !empty($_GET['act']) && ($_GET['act']==='detail'))
{
file_exists('artikel_detail.php') ? include 'artikel_detail.php' : die('Halaman detail artikel
tidak ditemukan');
}e
lse
{
$sqlArtikel=mysql_query("select * from artikel order by id desc");
echo"<table width=50%>";
while($hasilSqlArtikel=mysql_fetch_row($sqlArtikel))
{
$id=$hasilSqlArtikel[0];
$judul=$hasilSqlArtikel[1];
$konten=$hasilSqlArtikel[2];
$tgl=$hasilSqlArtikel[3];
$pengirim=$hasilSqlArtikel[4];
$url='?act=detail&idDet='.$id.'';
echo"<tr><td>";
echo"<b>$judul</b><br>$pengirim | $tgl<br>";
cuplikArtikel($konten,$url);
echo"<hr>";
}
}?
>
5.File artikel_detail.php
<?php
$idDetail=$_GET['idDet'];
$sqlDetail=mysql_query("select * from artikel where id='$idDetail'");
$hasilSqlDetail=mysql_fetch_array($sqlDetail);
$judul=$hasilSqlDetail['judul'];
$konten=$hasilSqlDetail['konten'];
$tgl=$hasilSqlDetail['tgl'];
$pengirim=$hasilSqlDetail['pengirim'];
echo"<table width=50%><tr><td>";
echo"<b>$judul</b><br>$pengirim | $tgl<br><br>$konten";
echo"</td></tr>
<tr><td align=right> <a href = artikel_cuplik.php> << back </a></td></tr>
</table>";
?>