|
|
|
ถามเรื่องการ เอาข้อมูลที่ Update หรือ Edit มาโชว์ครับ |
|
|
|
|
|
|
|
ในไฟล์จะเป็นแบบ เพิ่มแล้วข้อมูลโชว์ list ในหน้าแรกครับ แต่อยากให้ Edit แล้วโชว์ใน list ในหน้าแรกด้วยครับขอบคุณครับผม Code (PHP)
<? include_once "connDB.php"; ?>
<?
if($submit=="OK"){
if($id1==""){
$sql="INSERT INTO tbl_student set Auto_ID='".$Auto_ID."',Gender='".$Gender."', Title_Name='".$Title_Name."',FirstName='".$FirstName."', LastName='".$LastName."',Email='".$Email."',Tel='".$Tel."' ,Remark='".$Remark."'";
}else{
$sql="UPDATE tbl_student set Gender='".$Gender."',Title_Name='".$Title_Name."', FirstName='".$FirstName."',LastName='".$LastName."', Email='".$Email."',Tel='".$Tel."',Remark='".$Remark."' WHERE Auto_ID='".$id1."'" ;
}
mysql_query($sql);
}
if ($submit=="DEL"){
$sql="delete from tbl_student where Auto_ID ='".$id1."'";
mysql_query($sql);
}
?>
<script language="JavaScript">
function chkdel(){
if(confirm(' กรุณายืนยันการลบอีกครั้ง !!! ')){
return true;
}else{
return false;
}
}
function Check_txt(){
if(document.getElementById('Gender').value==""){
alert("กรุณาระบุ Gender ด้วยครับ");
document.getElementById('Gender').focus();
return false;
}
if(document.getElementById('Title_Name').value==""){
alert("กรุณาระบุ Title_Name ด้วยครับ");
document.getElementById('Title_Name').focus();
return false;
}
if(document.getElementById('FirstName').value==""){
alert("กรุณาระบุ FirstName ด้วยครับ");
document.getElementById('FirstName').focus();
return false;
}
if(document.getElementById('LastName').value==""){
alert("กรุณาระบุ LastName ด้วยครับ");
document.getElementById('LastName').focus();
return false;
}
if(document.getElementById('Email').value==""){
alert("กรุณาระบุ Email ด้วยครับ");
document.getElementById('Email').focus();
return false;
}else{
var Email=document.getElementById('Email').value;
if (!isEmail(Email)){
alert('E-mail ไม่ถูกต้อง กรุณาตรวจสอบและลองใหม่อีกครั้งค่ะ...');
document.getElementById('Email').focus();
return false;
}
}
}
function isEmail(str) {
var supported = 0;
if (window.RegExp) {
var tempStr = 'a';
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported)
return (str.indexOf('.') > 2) && (str.indexOf('@') > 0);
var r1 = new RegExp('(@.*@)|(\\.\\.)|(@\\.)|(^\\.)');
var r2 = new RegExp('^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$');
return (!r1.test(str) && r2.test(str));
}
</script><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>PHP CODE FATHER 2010 [www.code-father.com]</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<script type='text/javascript' language='javascript' src='date_time/prototype-1.js'></script>
<script type='text/javascript' language='javascript' src='date_time/prototype-date-extensions.js'></script>
<script type='text/javascript' language='javascript' src='date_time/behaviour.js'></script>
<script type='text/javascript' language='javascript' src='date_time/datepicker.js'></script>
<script type='text/javascript' language='javascript' src='date_time/behaviors.js'></script>
<link rel='stylesheet' href='date_time/datepicker.css'>
<body>
<center>
<div id="container">
<div id="content"><br><br>
<? if($submit=="" or $show=="OK"){?>
<center><form name="form1" method="post" action="student.php?show=OK&strSearch=Y">
<table width="98%" >
<tr>
<td width="50%"><div align="right">ค้นหา :<select name="Search2">
<option value="Gender" <? if($Search2=="Gender"){ ?>selected<? }?>>Gender</option>
<option value="Title_Name" <? if($Search2=="Title_Name"){ ?>selected<? }?>>Title_Name</option>
<option value="FirstName" <? if($Search2=="FirstName"){ ?>selected<? }?>>FirstName</option>
<option value="LastName" <? if($Search2=="LastName"){ ?>selected<? }?>>LastName</option>
<option value="Email" <? if($Search2=="Email"){ ?>selected<? }?>>Email</option>
</select></div>
</td>
<td width="64%"><input name="Search" type="text" size="20" value="<? echo $Search?>"onFocus="this.value = '';">
<input type="submit" name="submit" value="Search">
</td>
</tr>
</table>
</form></center>
<?
if(!isset($start)){
$start = 0;
$page=1;
}
$limit = '20';
if($strSearch=="Y"){
$Qtotal = mysql_query("select * from tbl_student Where ".$Search2." like '%".$Search."%' ");
}else{
$Qtotal = mysql_query("select * from tbl_student");
}
$total = mysql_num_rows($Qtotal);
if($strSearch=="Y"){
$Query = mysql_query("select * from tbl_student Where ".$Search2." like '%".$Search."%' order by Auto_ID DESC LIMIT $start,$limit");
}else{
$Query= mysql_query("select * from tbl_student order by Auto_ID DESC LIMIT $start,$limit");
}
$totalp = mysql_num_rows($Query);
$xx=$totalp+$start;
$yy=$start+1;
echo "ข้อมูลที่ ".$yy." ถึงข้อมูลที่ ".$xx;
printf(" | จากทั้งหมด %d รายการ ",$total);
printf(" | หน้าที่ %d <br />",$page);
?><br><br>
<table width="98%">
<tr bgcolor="#999999" height='40' >
<td align='center'><strong>Gender </strong></td>
<td align='center'><strong>Title_Name </strong></td>
<td align='center'><strong>FirstName </strong></td>
<td align='center'><strong>LastName </strong></td>
<td align='center'><strong>Email </strong></td>
<td width="8%"><a href="student.php?submit=Add&show="><center><img src="style/images/add.png" border="0"></center></a></td>
</tr>
<?
while($arr = mysql_fetch_array($Query)){
$autoid = $arr['Auto_ID'];
$i++;
if($i%2==0){
$bg = "#CCCCCC";
}else{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<? echo $bg?>" onMouseOver="this.style.backgroundColor='#CCFFCC'" onMouseOut="this.style.backgroundColor=''" valign="top">
<td align='center'><? echo $arr['Gender'] ?></td>
<td align='center'><? echo $arr['Title_Name'] ?></td>
<td align='center'><? echo $arr['FirstName'] ?></td>
<td align='center'><? echo $arr['LastName'] ?></td>
<td align='center'><? echo $arr['Email'] ?></td>
<td align="center">
<a href="student.php?submit=DEL&show=OK&id1=<? echo $autoid;?>" OnClick="return chkdel();"><img src="style/images/-.png" border="0"></a>
<a href="student.php?submit=Edit&id1=<? echo $autoid;?>"><img src="style/images/Tools.png" border="0"></a></td>
</tr>
<? }?>
</table>
<? }?>
<? if($submit=="Add"){?>
<form action="student.php?submit=OK&show=OK&id1=" method="post"onSubmit="return Check_txt()" enctype='multipart/form-data'>
<table width="98%">
<tr>
<td width='30%' align='right'>Auto_ID : </td>
<td width='70%'><input name='Auto_ID' id='Auto_ID' type='text' size='50'></td>
</tr>
<tr>
<td width='30%' align='right'>Gender : </td>
<td width='70%'><select name='Gender' id='Gender'>
<option value='ชาย'>ชาย</option>
<option value='หญิง'>หญิง</option>
</select>
* </td>
</tr>
<tr>
<td width='30%' align='right'>Title_Name : </td>
<td width='70%'><select name='Title_Name' id='Title_Name'>
<option value='นาย'>นาย</option>
<option value='นาง'>นาง</option>
<option value='นางสาว'>นางสาว</option>
</select>
* </td>
</tr>
<tr>
<td width='30%' align='right'>FirstName : </td>
<td width='70%'><input name='FirstName' id='FirstName' type='text' size='50'> * </td>
</tr>
<tr>
<td width='30%' align='right'>LastName : </td>
<td width='70%'><input name='LastName' id='LastName' type='text' size='50'> * </td>
</tr>
<tr>
<td width='30%' align='right'>Email : </td>
<td width='70%'><input name='Email' id='Email' type='text' size='50'> * </td>
</tr>
<tr>
<td width='30%' align='right'>Tel : </td>
<td width='70%'><input name='Tel' id='Tel' type='text' size='50'></td>
</tr>
<tr>
<td width='30%' align='right'>Remark : </td>
<td width='70%'><input name='Remark' id='Remark' type='text' size='50'></td>
</tr>
<tr height='50'>
<td></td>
<td align='left' valign='middle'><input type='submit' name='Submit' value=' บันทึก '> <input type='reset' name='Submit2' value='ล้างข้อมูล'> <input type='button' name='Submit222' value=' ยกเลิก ' onClick="document.location.href='student.php?show=OK'"></td>
</tr>
</table>
</form>
<? }?>
<? if($submit=="Edit"){
$sql="select * from tbl_student where Auto_ID ='".$id1."' ";
$tem = mysql_query($sql);
$row3=mysql_fetch_array($tem);
?>
<form action="student.php?submit=OK&show=OK&id1=<? echo $id1?>" method="post"onSubmit="return Check_txt();" enctype='multipart/form-data'>
<input type='hidden' name='Auto_ID' value="<?=$row3['Auto_ID']?>">
<table width="98%">
<tr>
<td width='30%' align='right'>Auto_ID : </td>
<td width='70%'><input name='Auto_ID' id='Auto_ID' type='text' size='50' value='<?=$row3["Auto_ID"]?>' disabled></td>
</tr>
<tr>
<td width='30%' align='right'>Gender : </td>
<td width='70%'><select name='Gender' id='Gender'>
<option value='ชาย' <? if($row3['Gender']=='ชาย') echo 'selected';?>>ชาย</option>
<option value='หญิง' <? if($row3['Gender']=='หญิง') echo 'selected';?>>หญิง</option>
</select>
* </td>
</tr>
<tr>
<td width='30%' align='right'>Title_Name : </td>
<td width='70%'><select name='Title_Name' id='Title_Name'>
<option value='นาย' <? if($row3['Title_Name']=='นาย') echo 'selected';?>>นาย</option>
<option value='นาง' <? if($row3['Title_Name']=='นาง') echo 'selected';?>>นาง</option>
<option value='นางสาว' <? if($row3['Title_Name']=='นางสาว') echo 'selected';?>>นางสาว</option>
</select>
* </td>
</tr>
<tr>
<td width='30%' align='right'>FirstName : </td>
<td width='70%'><input name='FirstName' id='FirstName' type='text' size='50' value='<?=$row3["FirstName"]?>'> * </td>
</tr>
<tr>
<td width='30%' align='right'>LastName : </td>
<td width='70%'><input name='LastName' id='LastName' type='text' size='50' value='<?=$row3["LastName"]?>'> * </td>
</tr>
<tr>
<td width='30%' align='right'>Email : </td>
<td width='70%'><input name='Email' id='Email' type='text' size='50' value='<?=$row3["Email"]?>'> * </td>
</tr>
<tr>
<td width='30%' align='right'>Tel : </td>
<td width='70%'><input name='Tel' id='Tel' type='text' size='50' value='<?=$row3["Tel"]?>'></td>
</tr>
<tr>
<td width='30%' align='right'>Remark : </td>
<td width='70%'><input name='Remark' id='Remark' type='text' size='50' value='<?=$row3["Remark"]?>'></td>
</tr>
<tr height="50">
<td></td>
<td><input type="submit" name="Submit" value=" บันทึก "> <input type="button" name="Submit222" value=" ยกเลิก " onClick="document.location.href='student.php?show=OK'"></td>
</tr>
</table>
</form>
<? }?>
</div>
<div id="footer">
<? if($submit=="" or $show=="OK"){
$page = ceil($total/$limit);
for($i=1;$i<=$page;$i++){
if($_GET['page']==$i){
echo "[<a href='?start=".$limit*($i-1)."&page=$i&strSearch=$strSearch&Search=$Search&Search2=$Search2'><B>$i</B></A>]";
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i&strSearch=$strSearch&Search=$Search&Search2=$Search2'>$i</A>]";
}}} ?>
</div>
</div>
</center>
</body>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2015-04-27 21:50:16 |
By :
mamafaka |
View :
720 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PHP MySQL Edit/Update Data Record
PHP MySQL DropDownList / Listmenu / ListBox
|
|
|
|
|
Date :
2015-04-28 09:50:26 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|