aku leh ajarkan...
step 1:
buatkan database untuk form ko:
contohnye name database ko 'form' n name table ko 'contactus'
buat row untuk 'name' 'email' 'contact' and message
or ko just guna syntax sql aku nie:
CREATE TABLE `contactus` (
`num` INT( 10 ) NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 30 ) NOT NULL ,
`email` VARCHAR( 30 ) NOT NULL ,
`contact` VARCHAR( 30 ) NOT NULL ,
`message` VARCHAR( 60 ) NOT NULL
) ENGINE = MYISAM ;
copy paste kt syntax sql n run..
step 2:
buatkan form:
kalau nak ikut script aku leh gak :
ko tengok kt action tue, tu yang akan process kopnye form.
<form method="POST" action="process.php">
<fieldset style="padding: 2">
<legend>Contact us</legend>
Name :<input type="text" name="name" id="name" size="41"><p>Email :<input type="text" name="email" id="email" size="41"></p>
<p>Contact No:<input type="text" name="contact" id="contact" size="41"></p>
<p>Message :</p>
<p><textarea rows="8" name="massage" id="message" cols="46"></textarea></p>
<p> </p>
</fieldset><p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
save kan sebagai 'form.php'
copy je script tu.. paste kat php editor atau ko leh guna note pad save as form.php
step 3:
ko buatkan script processor untuk form ko script tu camnie:
<?
$db_hostname = "localhost"; //kebiasaannya "localhost"
$db_username = "root"; //user name ko
$db_pass = ""; //kalau ade password letak je password
$db_name = "form"; //name database
$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);
$sql="INSERT INTO contactus (name,email,contact,message) VALUES
('$_POST[name]','$_POST','$_POST[contact]','$_POST[message]')";
$result=mysql_query($sql);
if($result){
header("location:berjayadihantar.php");
}
else
die('Error: ' .mysql_error());
?>
save as process.php macam kat action method di form td
step 4:
buat kan page untuk form yang berjaya:
copy kan script nie:
<!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>
<style type="text/css">
<!--
.style1 {
color: #BBBBBB;
font-size: 9px;
}
-->
</style>
</head>
<body>
<div align="center">
<p>Berjaya Dihantar</p>
<p> </p>
<p class="style1">tutorial by:</p>
<p class="style1">aredsterz 2010</p>
</div>
</body>
</html>
save as berjayadihantar.php
jadi.. dari tutorial nie ko leh belajar dua benda.. satu penggunaan script processor dan satu lagi kombinasi php dengan html
saya ade bace komen2 dari pengguna lain, n ade pengguna yang tak tahu bahawa scrpt PHP boleh ber gabung dengan HTML..