php การจัดการเกี่ยวกับฐานข้อมูลเบื้องต้น......
#connect.php
$host="localhost";
$user="root";
$pass="1234";
$db_name="db_student";
mysql_connect($host,$user,$pass) or die ("Can't connect to server");
mysql_select_db($db_name) or die ("Can't Connect database");
mysql_query("SET NAMES tis620");
#index.php
<body>
<form id="form1" name="form1" method="post" action="index.php">
<table width="500" border="1" align="center">
<tr>
<td>ค้นหาโดย</td>
<td><label for="search"></label>
<select name="search" id="search">
<option value="SCI">SCI</option>
<option value="BAIT">BAIT</option>
<option value="all">เลือกทั้งหมด</option>
</select></td>
<td><input type="submit" name="Submit" id="button" value="ค้นหา" /></td>
</tr>
</table>
</form>
<p> </p>
<table width="900" border="1" align="center">
<tr>
<td width="120">รหัสนักศึกษา</td>
<td width="157">ชื่อ</td>
<td width="154">นามสกุล</td>
<td width="197">สาขา</td>
<td width="238">คณะ</td>
</tr>
<?php
include("connect.php");
$search=$_POST['search'];
$sql="SELECT
tb_faculty.std_id,
tb_faculty.brance,
tb_faculty.faculty,
tb_student.std_id,
tb_student.std_name,
tb_student.std_surname
FROM
tb_faculty
INNER JOIN tb_student ON tb_faculty.std_id = tb_student.std_id
WHERE
tb_faculty.faculty = '$search'
";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rs['std_id'];?></td>
<td><?php echo $rs['std_name'];?></td>
<td><?php echo $rs['std_surname'];?></td>
<td><?php echo $rs['brance'];?></td>
<td><?php echo $rs['faculty'];?></td>
</tr>
<?php } ?>
</table>
<p> </p>
<p><a href="std_form.php">เพิ่มข้อมูล</a></p>
</body>
#std_form.php
<body>
<form id="form1" name="form1" method="post" action="std_insert.php">
<table width="500" border="1" align="center">
<tr>
<td width="136" align="right" bgcolor="#999999">รหัสนักศึกษา</td>
<td width="348" bgcolor="#CCCCCC">
<input name="txt_id" type="text" id="txt_id" size="25" /></td>
</tr>
<tr>
<td align="right" bgcolor="#999999">ชื่อ</td>
<td bgcolor="#CCCCCC">
<input name="txt_name" type="text" id="txt_name" size="25" /></td>
</tr>
<tr>
<td align="right" bgcolor="#999999">นามสกุล</td>
<td bgcolor="#CCCCCC">
<input name="txt_surname" type="text" id="txt_surname" size="25" /></td>
</tr>
<tr>
<td align="right" bgcolor="#999999">สาขา</td>
<td bgcolor="#CCCCCC">
<input name="txt_brance" type="text" id="txt_brance" size="25" /></td>
</tr>
<tr>
<td align="right" bgcolor="#999999">คณะ</td>
<td bgcolor="#CCCCCC">
<input name="txt_faculty" type="text" id="txt_faculty" size="25" /></td>
</tr>
<tr bgcolor="#999999">
<td align="center"> </td>
<td align="center"><input type="submit" name="button" id="button" value="บันทึก" />
<input type="reset" name="button2" id="button2" value="ยกเลิก" /></td>
</tr>
</table>
</form>
</body>
#std_insert.php
<?php
include("connect.php");
$std_id=$_POST['txt_id'];
$std_name=$_POST['txt_name'];
$std_surname=$_POST['txt_surname'];
$std_brance=$_POST['txt_brance'];
$std_faculty=$_POST['txt_faculty'];
$sql="insert into tb_student value('$std_id','$std_name','$std_surname')";
echo $sql;
$result=mysql_query($sql);
if($result){
$sql1="insert into tb_faculty value('$std_id','$std_brance','$std_faculty')";
$result1=mysql_query($sql1);
if($result1){
echo "บันทึกสำเร็จ";
}else{
echo "error 2 !!!";
}
}else{
echo "error1 !!!";
}
?>
<br/><br/><br/><br/>
<a href="index.php">กลับหน้าหลัก </a>
-------------------------------------------------------------------------------------------------Tag : PHP, MySQL
ประวัติการแก้ไข 2014-11-30 15:15:27
Date :
2014-11-30 14:52:30
By :
Diw Diw
View :
702
Reply :
2
Date :
2014-11-30 15:52:31
By :
mr.win
Date :
2014-11-30 16:01:09
By :
LAGO
Load balance : Server 05