|
 |
|
ขอสอบถาเกี่ยวกับการเขียน form php ครับ.....ผมจะเขียนให้มันเก็บตัวแปรลงในฟิล total คับ |
|
 |
|
|
 |
 |
|
ก็เขียนโดยการอ้าง year_y มาใช้เลยครับ  
|
 |
 |
 |
 |
Date :
2014-12-15 14:50:53 |
By :
LAGO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
ปริญญาโท :<td class="normal"><input name="year_y" type="text" id="year_y=2" size="10" />
แบบนี้ป่ะคับ
|
 |
 |
 |
 |
Date :
2014-12-15 15:03:53 |
By :
stepartz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
 การเพิ่มข้อมูลนี้เป็นการแก้ไขข้อมูลเดิมหรือบันทึกข้อมูลใหม่
|
 |
 |
 |
 |
Date :
2014-12-15 17:55:53 |
By :
LAGO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หน้า form คุณก็มี
<input type="text" name="1" value="">->สำหรับ ตรี
<input type="text" name="2" value="">->สำหรับ โท
<input type="text" name="3" value="">->สำหรับ เอก
ตอน insert ก็สร้างแบบนี้อะ่ครับ ไม่รู้ผมเข้าใจถูกไหมอะ
insert into degree (total)value('".$_REQUEST["1"]."')
insert into degree (total)value('".$_REQUEST["2"]."')
insert into degree (total)value('".$_REQUEST["3"]."')
|
 |
 |
 |
 |
Date :
2014-12-15 18:36:21 |
By :
nut_ch31 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ต้องไปนอมอลไลมาใหม่ครับ...มันเป็นการออกแบบ DB ที่ผิดพลาดละ
|
 |
 |
 |
 |
Date :
2014-12-15 19:41:32 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จังแล้วน่าออกแบบระบบใหม่นะครับผมดูแล้วมันยังไงไม่รู้ ลองเอาตัวไปประยุกต์ดูครับ
หน้าแสดงปี index.php
Code (PHP)
<?
session_start();
include('config.php');
?>
<!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>
</head>
<body>
<tr>
<td bgcolor="#FF9900"><div align="center">เลือกปีการศึกษาที่ต้องการ</div></td>
</tr>
<tr>
<td valign="top"><div align="center">
<table width="209" border="0" cellspacing="2" cellpadding="3">
<tr>
<td width="58%"><?
$yearSQL = "select distinct year_name,id from year order by year_name";
$yearQRY = mysql_db_query($dbname, $yearSQL);
$a=0;
while($yearRS = mysql_fetch_object($yearQRY)){
$year_name = $yearRS -> year_name;
$id = $yearRS -> id;
$a++;
echo " <br><a href=\"show_year.php?cat=".$id."\">".$year_name."</b></a>";
echo "<hr size=1>";
?>
<?
}
?></td>
</tr>
</table>
</div></td>
</tr>
</body>
</html>
หน้ารับข้อมูลระครับ show_year.php
Code (PHP)
<?
session_start();
include('config.php');
?>
<!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=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<?
$yearSQL = "select * from year where id='".$cat."' order by id";
$yearQRY = mysql_db_query($dbname, $yearSQL);
$a=0;
while($yearRS = mysql_fetch_object($yearQRY)){
$year_name = $yearRS -> year_name;
$id = $yearRS -> id;
$a++;
?>
<table width="77%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC">
<tr bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'">
<td width="26%" bgcolor="#FF9900"><div align="center">ระดับ</div></td>
<td width="12%" bgcolor="#FF9900"><div align="center">จำนวนนักศึกษา</div></td>
<td width="12%" bgcolor="#FF9900"> </td>
</tr>
<?
$degreeSQL = "select * from degree where year_y='".$id."' order by id";
$degreeQRY = mysql_db_query($dbname, $degreeSQL);
$t=0;
while($degreeRS = mysql_fetch_object($degreeQRY)){
$id = $degreeRS -> id;
$degree_name = $degreeRS -> degree_name;
$year_y = $degreeRS -> year_y;
$total = $degreeRS -> total;
$t++;
?>
<tr bgcolor="#FFFFFF" onMouseOver="this.bgColor = '#FFE1FF'" onMouseOut="this.bgColor = '#FFFFFF'">
<td ><div align="left"><font color="#990000">
<? echo $degree_name; ?></font></div></td>
<td><div align="center"><font color="#990000"><? echo $total; ?></font></div></td>
<td><label></label>
<form action="save_year.php" method="post" enctype="multipart/form-data" name="form2" target="xData">
<input name="id" type="hidden" id="id" value="<?=$id; ?>" />
<input name="id1" type="hidden" id="id1" value="<?=$year_y; ?>" />
<input name="total" type="text" id="total" value="<?=$total;?>" size="5" />
<input type="submit" name="button" id="button" value="บันทึก" />
</form> </td>
</tr>
<?
}}
?>
</table>
<div align="center"></div>
</body>
</html>
หน้าบันทึกข้อมูลปีนะครับ save_year.php
Code (PHP)
<?
session_start();
include('config.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<?
if($id<1){
$yearSQL = "insert into degree set
degree_name='$degree_name',
year_y='$year_y',
total='$total'";
mysql_db_query($dbname, $yearSQL);
$id = mysql_insert_id();
} else {
$yearSQL = "update degree set
total='$total'
where id='".$id."'";
mysql_db_query($dbname, $yearSQL);
}
echo "<script>alert('ระบบบันทึกข้อมูลเรียบร้อยแล้ว'); window.parent.location='show_year.php?cat=".$id1."';</script>";
?>
หน้าเชื่อมต่อ config.php
Code (PHP)
<?
$hostname = "localhost";
$dbuser = "root";
$dbpassword = "1234";
$dbname = "degree";
mysql_connect($hostname, $dbuser, $dbpassword) or die("Don't Connect Database");
mysql_select_db($dbname)or die("Don't Connect Database!!");
mysql_query("set NAMES tis620 ");
?>
ปล. ประยุกต์นะครับเพราะผมไม่แน่ใจว่าต้องการแบบไหนอย่างไร (งงอยู่ 555)
|
ประวัติการแก้ไข 2014-12-17 10:37:44 2014-12-17 10:39:50
 |
 |
 |
 |
Date :
2014-12-17 10:36:05 |
By :
LAGO |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|