by miss_hufflepuff Mon May 25, 2009 11:54 am
nak mintak tolong tgkkan all these codes eh.. tak tau nape tak leh execute bile try bukak di browser, dah gune xampp,ni pasal db student..dlu penah wat ni, menjadi i mean leh execute kt browser, skang cube tak leh lak.. sy nak jdkan ni contoh tuk wat db jawatankuasa sy tu, application nyer lebeh kuang jer,nk bg yg tu mcm byk sgt.. kang korang pening lak hehe.. syukran, nandre, arigato, shesheni, time kasih..
ni table login_sample.php
- Code:
<?
if((!$_POST['un']) || (!$_POST['pass']))
{
header("Location: file:///C:/Program%20Files/xampp/htdocs/cikziziannyercontoh/login_sample.html");
exit;
}
$db_name = "db";
$table_name = "login";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $conncection) or die (mysql_error());
$sql = "SELECT * FROM WHERE $table_name WHERE username = '$_POST[un]' AND password = '$_POST[pass]'";
$result = @mysql_query($sql, $connection) or die (mysql_error());
$num = @mysql_num_rows($result);
mysql_close($connection);
if($num != 0)
{
session_start();
session_register('valid');
$_SESSION[valid] = "yes";
header("Location: menu_sample.php");
exit;
}
else
$msg ="<p>PLEASE TRY AGAIN!</p>";
?>
<html>
<head>
<title>login_sample</title>
</head>
<body>
<?php echo "$msg";
?>
</body>
</html>
ni table login_sample.html
- Code:
<html>
<head>
<title>Login form</title>
</head>
<body bgcolor="#FF9966">
<center>
<form method = "post" action="login_sample.php">
<h1>User Name :
<input type = "text" name = "un">
<br>
Password :
<input type = "password" name = "pass"><br>
<input type = "Submit" name = "b_login" value = "LOGIN">
<input type = "reset" name = "b_reset" value = "RESET">
</h1>
</center>
</form>
</body>
</html>
ni table insert_sample.html
- Code:
<html>
<head>
<title>Insertion form</title>
</head>
<body>
<form method = "post" action = "insert.php">
<table border = "1">
<tr>
<td>ID</td>
<td><input type ="text" name ="id"></td>
</tr>
<tr>
<td>Name</td>
<td><input type = "text" name = "nama"> </td>
</tr>
</table>
<input type = "submit" name = "subtn" value = "Add">
<input type = "reset" name = "rebtn" value = "Reset">
</form>
</body>
</html>
ni insert.php
- Code:
<?php
include_once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$sql = "INSERT INTO $table_name(student_id, student_name)";
VALUES('$_POST[id]','$_POST[nama]');
$result = @mysql_query($sql,$connection) or die (mysql_error());
mysql_close($connection);
?>
<html>
<head>
</head>
<body>
<table border = "1">
<tr>
<td>ID</td>
<td><?php echo "$_POST[id]"; ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo "$_POST[nama]"; ?></td>
</tr>
</table>
<P> <a href = "menu_sample.php">back</a></P>
</body>
</html>
ni table menu_sample.php
- Code:
<?php
include_once("session.php");
//session_start();
//if($_SESSION['valid'] ! = "yes")
//{
// header("Location: login_sample.html");
// exit;
//}
?>
<html>
<head>
<title>Untitled Document</title>
<body>
<h1>MENU</h1>
<ul>
<li><a href = "insert_sample.html">INSERT</a></li>
<li><a href = "view_all.php">VIEW</a></li>
<li><a href = "view_all_update.php">UPDATE</a></li>
<li><a href = "view_all_delete.php">DELETE</a></li>
</ul>
<a href = logout.php>logout</a>
</body>
</html>
ni table view.php
- Code:
<?php
include_once("session.php");
$db_name ="db";
$table_name = "student";
$connection = @mysql_connect("localhost","root","") or die (mysql_error());
$db = @mysql_select_db ($db_name, $connection) or die (mysql_error());
$sql = "SELECT student_id, student_name FROM $table_name";
$result = @mysql_query($sql, $connection) or die (mysql_error());
while($row = mysql_fetch_array ($result))
{
$id=$row['student_id'];
$name=$row['student_name'];
$display.="<tr><td><a href = view_all_detail.php ? id=$id>$id</a></td><td>$name</td></tr>";
}
mysql_close($connection);
?>
<html>
<head>
<title>View All</title>
</head>
<body>
<table border = 1>
<?php echo "$display"; ?>
</table>
<p><a href="menu_sample.php">back</a></p>
</body>
</html>
ni table view_all_detail.php (kt sini sy ingat nak apply drop down box, maknenye, kite pilih nama student atau id student tu n then dia akan kuarkan infonye, contoh kite pilih id n dia kuar nama or vice versa la..just nak kan gambaran basic, maybe dr sini sy leh teruskan tuk database jawatankuasa saye)
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$id = $_GET[id];
$sql = "SELECT * FROM $table_name WHERE student_id = '$id'";
$result = @mysql_query($sql, $connection) or die (mysql_error());
while($row = mysql_fetch_array($result))
{
$id = $row['student_id'];
$name = $row['student_name'];
}
$display .= "<TABLE BORDER = 1><tr><th>ID</th><th>NAME</th></tr><tr><td>$id</td><td>$name</td></tr></TABLE>";
mysql_close($connection);
?>
<html>
<head>
<title>View details</title>
</head>
<body>
<?php echo "$display"; ?>
</TABLE>
<P> <a href = "view_all.php">back </a></P>
</body>
</html>
ni table view_all_update.php
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$sql = "SELECT student_id, student_name FROM $table_name";
$result = @mysql_query($sql, $connection) or die (mysql_error());
while($row = mysql_fetch_array($result))
{
$id = $row['student_id'];
$name = $row['student_name';
$display .= "<tr><td><a href = view_detail_update.php?id=$id>$id</a></td><td>$name</td></tr>";
}
mysql_close($connection);
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<TABLE BORDER =1>
<?php echo "$display"; ?>
</TABLE>
<P> <a href = "menu_sample.php">back </a></P>
</body>
</html>
ni table view_detail_delete.php
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$id = $_GET[id];
$sql = "SELECT * FROM $table_name WHERE student_id = '$id'";
$result = @mysql_query($sql, $connection) or die (mysql_error());
while($row = mysql_fetch_array($result))
{
$id = $row['student_id'];
$name = $row['student_name'];
}
$display .="<form method = \"post\"action = \"delete_record.php?id=$id\"><TABLE BORDER = 1><tr><td>ID : </td><td> $id </td></tr> <tr><td>NAME : </td> <td>$name</td></tr></TABLE><br> <input type = \"Submit\" value=\"DELETE\"></form>";
mysql_close($connection);
?>
<html>
<head>
<title>Untitiled Document</title>
</head>
<body>
<?php echo "$display"; ?>
</TABLE>
<P> <a href = "view_all_update.php">back </a></P>
</body>
</html>
ni table view_detail_update.php
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$id = $_GET[id];
$sql = "SELECT * FROM $table_name WHERE student_id = '$id'";
$result = @mysql_query($sql, $connection) or die (mysql_error());
while($row = mysql_fetch_array($result))
{
$id = $row['student_id'];
$name = $row['student_name';
}
$display .= "<form method = \"post\"action=\"update_record.php?id=$id\"><TABLE BORDER =1><tr><td>ID : </td><td>$id</td></tr><tr><td>NAME : </td><td><input type = \"text\"name =\"nama\"value =\"$name\"></td></tr></TABLE><br><input type = \"Submit\" value = \"UPDATE\"></form>";
mysql_close($connection);
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php echo "$display"; ?>
<P> <a href = "view_all_update.php">back </a></P>
</body>
</html>
ni table view_all_delete.php
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$sql = "SELECT student_id, student_name FROM $table_name";
$result = @mysql_query($sql, $connection) or die (mysql_error());
while($row = mysql_fetch_array($result))
{
$id = $row['student_id'];
$name = $row['student_name'];
$display .= "<tr><td><a href = view_detail_delete.php?id=$id>$id</a></td><td>$name</td></tr>";
}
mysql_close($connection);
?>
<html>
<head>
<title>View details</title>
</head>
<body>
<TABLE BORDER = 1>
<?php echo "$display"; ?>
</TABLE>
<P> <a href = "menu.php">back </a></P>
</body>
</html>
ni table update_record.php
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$id = $_GET[id];
$sql = "UPDATE $table_name SET student_name = '$_POST[nama]' WHERE student_id = '$id'";
$result = @mysql_query($sql, $connection) or die (mysql_error());
echo "the record has been updated!<a href = \"view_all.php\">view again</a>">;
?>
ni table delete_record.php
- Code:
<?php
include once("session.php");
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "root", "") or die (mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error());
$id = $_GET[id];
$sql = "DELETE FROM $table_name WHERE student_id = '$id'";
$result = @mysql_query($sql, $connection) or die (mysql_error());
mysql_close($connection);
?>
<html>
<head>
<title>Deleting</title>
</head>
<body>
<P><? echo "$id"; ?> has been deleted!</P>
<P> <a href = "view_all_delete.php">back </a></P>
</body>
</html>
ni table session.php
- Code:
<?php
session_start();
if($_SESSION['valid'] ! = "yes")
{
header("Location : login_sample.html");
exit;
}
?>
ni table tes_sql.php
- Code:
<?php
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "azizia", "aaa");// or die (mysql_error());
if($conn==false)
{
echo "<br>database error";
die("<br>Mysql error:".mysql_error());
}
$db = @mysql_select_db($dbname, $conn) or die (mysql_error());
$sql = "SELECT * FROM $table_name";
$rst = @mysql_query($sql, $conn) or die (mysql_error());
$num = @mysql_num_rows($rst);
$out = "";
while($row=mysql_fetch_array($rst))
{
$id = $row["student_id"];
$name = $row["student_name"];
$out.="<br>$id     $name";
}
mysql_close($conn);
?>
<html>
<head>
<h5>ID     NAME<h5>
<?php echo "$out";?>
</body>
</html>
ni table logout.php
- Code:
<?php
$db_name = "db";
$table_name = "student";
$connection = @mysql_connect("localhost", "azizia", "aaa");// or die (mysql_error());
if($conn==false)
{
echo "<br>database error";
die("<br>Mysql error:".mysql_error());
}
$db = @mysql_select_db($dbname, $conn) or die (mysql_error());
$sql = "SELECT * FROM $table_name";
$rst = @mysql_query($sql, $conn) or die (mysql_error());
$num = @mysql_num_rows($rst);
$out = "";
while($row=mysql_fetch_array($rst))
{
$id = $row["student_id"];
$name = $row["student_name"];
$out.="<br>$id     $name";
}
mysql_close($conn);
?>
<html>
<head>
<h5>ID     NAME<h5>
<?php echo "$out";?>
</body>
</html>