|
|
|
ผม แก้ไข ข้อมูล 1 ข้อแต่ข้อมูลใน phpmyadmin เปลี่ยนเหมือนกันหมด ทั้งที่แก้ไปแค่ id เดียว ช่วยหน่อยครับ |
|
|
|
|
|
|
|
ผมสร้าง from แก้ไขข้อมูลที่มีรูปภาพ ลอง test ดูแล้วว่าแก้ไขได้ แต่พอไปดูที่ phpmyadmin ข้อมูล เหมือนกันทุกอย่างทึกไอดี
ทั้งๆ แก้ไขไปแค่้ข้อมูลเดียว 1 id
หน้า code update ข้อมูล
Code (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></title>
</head>
<body>
<?
list($day, $month, $year) = split('[/.-]', $date);
$year = $year - 543;
$date= "$year-$month-$day";
list($day, $month, $year) = split('[/.-]', $p_date);
$year = $year - 543;
$p_date= "$year-$month-$day";
list($day, $month, $year) = split('[/.-]', $aut_date);
$year = $year - 543;
$aut_date= "$year-$month-$day";
//*** Update Record ***//
//$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
//$objDB = mysql_select_db("security");
include "config.php";
$sql = "UPDATE secur_data ";
$sql="update secur_data set
hosname = '$hosname' , province = '$province', tower = '$tower', place = '$place' , date = '$date' ,time = '$time' , cause_a = '$cause_a', hazards = '$hazards', s1 = '$s1',d1 = '$d1', secur_name = '$secur_name', danger_name = '$danger_name', analyzing = '$analyzing' , suggestion = '$suggestion' , comment = '$comment' , p_pname = '$p_pname',p_sname='$p_sname',p_date='$p_date', pic = '$pic' , aut_pname = '$aut_pname' , aut_sname = '$aut_sname' , aut_date = '$aut_date',registration='$registration' where '$id' = '".$_GET["id"]."'";
$result = mysql_query($sql);
if($_FILES["pic"]["name"] != "")
{
if(move_uploaded_file($_FILES["pic"]["tmp_name"],"upload/".$_FILES["pic"]["name"]))
{
//*** Delete Old File ***//
@unlink("upload/".$_POST["hdpic"]);
//*** Update New File ***//
$sql = "UPDATE secur_data ";
$sql .=" SET pic = '".$_FILES["pic"]["name"]."' WHERE id = '".$_GET["id"]."' ";
$result = mysql_query($sql);
echo "Copy/Upload ข้อมูลเรียบร้อย<br>";
print"<META HTTP-EQUIV='refresh' content='1;URL=showdata1.php?id=$id'>";
}
}
mysql_close();
?>
</body>
</html>
ภาพหลังจากแก้ไขข้อมูล ข้อมูลเหมือนกันหมดเลย
หน้า form ส่งข้อมูล
Code (PHP)
<html>
<head>
<script language='javascript' src='popcalendar.js'></script>
<title><? include "config.php";echo "$title";?></title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-874">
<style type="text/css">
<!--
.regular12 {font-size: 12px;
font-family: "ms Sans Serif";
}
.white14bold {font-size: 14px; font-family: "ms Sans Serif"; font-weight: bold; color: #FFFFFF; }
.star {color: #FF0000}
-->
</style>
<link rel="stylesheet" type="text/css" href="anylinkmenu.css" /><link rel="stylesheet" type="text/css" href="anylinkmenu.css" />
<script type="text/javascript" src="menucontents.js"></script>
<script type="text/javascript" src="anylinkmenu.js">
/***********************************************
* AnyLink JS Drop Down Menu v2.0- ? Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Project Page at http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm for full source code
***********************************************/
</script>
<script type="text/javascript">
//anylinkmenu.init("menu_anchors_class") //Pass in the CSS class of anchor links (that contain a sub menu)
anylinkmenu.init("menuanchorclass")
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (securi2_resize.jpg) -->
<table width="968" height="801" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
<td colspan="2" rowspan="6">
<img src="images/index_01.jpg" width="30" height="248" alt=""></td>
<td>
<img src="images/index_02.jpg" width="184" height="73" alt=""></td>
<td colspan="2" rowspan="6">
<img src="images/index_03.jpg" width="754" height="248" alt=""></td>
</tr>
<tr>
<td>
<a href="add_data.php"><img src="images/index_04.jpg" alt="" width="184" height="32" border="0"></a></td>
</tr>
<tr>
<td><a href="show_data.php"><img src="images/index_05.jpg" alt="" width="184" height="34" border="0"></a></td>
</tr>
<tr>
<td>
<a href="" class="menuanchorclass someotherclass" rel="anylinkmenu2[click]" rev="lr"><img src="images/index_06.jpg" width="184" height="35" border="0"></a></td>
</tr>
<tr>
<td>
<a href="searchedit.php"><img src="images/index_07.jpg" alt="" width="184" height="32" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/index_08.jpg" width="184" height="42" alt=""></td>
</tr>
<?
include "config.php";
$sql = "SELECT * FROM $tbldata WHERE id = '".$_GET["id"]."' ";
//$sql="select * from $tbldata where id='$id'";
$result= mysql_query($sql);
$row=mysql_fetch_array($result);
// $id=$row['cat_id'];
// $catename=$row['cat_name'];
$id = $row['id'];
$hosname=$row['hosname'];
$province=$row['province'];
$tower = $row['tower'];
$place = $row['place'];
$date = $row['date'];
$time = $row['time'];
$cause_a = $row['cause_a'];
$hazards = $row['hazards'];
$s1=$row['s1'];
$d1=$row['d1'];
$secur_name = $row['secur_name'];
$danger_name = $row['danger_name'];
$analyzing = $row['analyzing'];
$suggestion = $row['suggestion'];
$comment = $row['comment'];
$p_pname = $row['p_pname'];
$p_sname = $row['p_sname'];
$p_date = $row['p_date'];
$pic = $row['pic'];
$aut_pname = $row['aut_pname'];
$aut_sname = $row['aut_sname'];
$aut_date = $row['aut_date'];
$registration = $row['registration'];
?>
<tr>
<td background="images/index_09.jpg" bgcolor="#41A72A"><img src="images/index_09.jpg" width="6" height="486"></td>
<td colspan="3" valign="top"><form name="form1" method="post" action="save_editdata.php?id=<?=$_GET["id"];?>" enctype="multipart/form-data">
<table width="958" align="center" cellpadding="2" cellspacing="0">
<tr>
<td height="26" colspan="8" bgcolor="#00CC66"><label></label>
<label class="white14bold"> </label>
<div align="center"><span class="white14bold">แก้ไขข้อมูล</span></div></td>
</tr>
<tr>
<td width="197" bgcolor="#E8FFE8"> </td>
<td colspan="3" bgcolor="#E8FFE8"> </td>
<td width="147" bgcolor="#E8FFE8"> </td>
<td colspan="3" bgcolor="#E8FFE8"> </td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">ชื่อโรงพยาบาล</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<select name="hosname" id="hosname">
<option value="<? echo"$hosname"; ?>" selected><? echo"$hosname"; ?></option>
<?
$sql="select id,hosname from $tblhos order by id";
$result1=mysql_query($sql);
$num = mysql_num_rows($result1);
$i=0;
while ($i < $num)
{
$fet1 = mysql_fetch_array($result1);
$id = $fet1[0];
$hos = $fet1[1];
//while($fetch=mysql_fetch_array($result)){
echo"<option value='$hos'>$hos</option>";
$i++;
}
?>
</select>
</label></td>
<td bgcolor="#E8FFE8" class="regular12"><div align="right">จังหวัด</div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<select name="province" id="province">
<option value="<? echo"$province"; ?>" selected><? echo"$province"; ?></option>
<?
$sql="select * from $tblprov ";
$result=mysql_query($sql);
while($fetch=mysql_fetch_array($result)){
?>
<option value="<?=$fetch['province_name']?>"><?=$fetch['province_name']?></option>
<? } ?>
</select>
</label></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">อาคาร / ตึก</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<input name="tower" type="text" id="tower"value="<?php echo "$tower"?>"/>
</label></td>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">จุด/สถานที่ตรวจพบ</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<input name="place" type="text" id="place"value="<?php echo "$place"?>" />
</label></td>
</tr>
<tr>
<td bgcolor="#E8FFE8" class="regular12"><div align="right">วันที่</div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<input name="date" type=text id="date" onKeyPress="kod_pum()" size="12" value="<?
list($year, $month, $day) = split('[/.-]', $date);
$year = $year + 543;
$date= "$day/$month/$year";
echo "$date"; ?>">
<script language='javascript'>
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this,\"date\", \"dd/mm/yyyy\")' value=' Date ' style='font-size:11px'>")
}
</script>
</label></td>
<td bgcolor="#E8FFE8" class="regular12"><div align="right">เวลา</div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<input name="time" type="text" id="time" value="<?php echo "$time"?>" size="8" />
</label></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">รายละเอียดความไม่<br>
ปลอดภัยที่ตรวจพบ</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<textarea name="cause_a" cols="40" rows="4" id="cause_a"><?php echo "$cause_a"?></textarea>
</label></td>
<td bgcolor="#E8FFE8">
<div align="right"><span class="regular12">อันตรายที่เกิด/อาจเกิด</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><textarea name="hazards" cols="40" rows="4" id="hazards"><?php echo "$hazards"?>
</textarea></td>
</tr>
<tr>
<td rowspan="3" bgcolor="#E8FFE8"><span class="regular12">
<div align="right"><span class="regular12">ระดับความไม่ปลอดภัย</span></div></td>
<td colspan="3" rowspan="2" bgcolor="#E8FFE8"><label><span class="regular12">ระดับA</span>
<input name="s1" type="radio" value="1"<?=($s1=="1")?"checked":""; ?>>
<span class="regular12">ระดับB</span>
<input name="s1" type="radio" value="2"<?=($s1=="2")?"checked":""; ?>>
<span class="regular12">ระดับC</span>
<input name="s1" type="radio" value="3"<?=($s1=="3")?"checked":""; ?>>
<span class="regular12">ระดับD</span>
<input name="s1" type="radio" value="4"<?=($s1=="4")?"checked":""; ?>>
</label></td>
<td rowspan="3" bgcolor="#E8FFE8"><div align="right"><span class="regular12">ระดับอันตราย</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><p><span class="regular12">ระดับ1</span>
<input name="d1" type="radio" value="1"<?=($d1=="1")?"checked":""; ?>>
<span class="regular12">ระดับ2</span>
<input name="d1" type="radio" value="2"<?=($d1=="2")?"checked":""; ?>>
<span class="regular12">ระดับ3</span>
<input name="d1" type="radio" value="3"<?=($d1=="3")?"checked":""; ?>>
<span class="regular12">ระดับ4</span>
<input name="d1" type="radio" value="4"<?=($d1=="4")?"checked":""; ?>>
<br>
</p> </td>
</tr>
<tr>
<td colspan="3" bgcolor="#E8FFE8"><span class="regular12">ระดับ5</span>
<input name="d1" type="radio" value="5"<?=($d1=="5")?"checked":""; ?>>
<span class="regular12">ระดับ6</span>
<input name="d1" type="radio" value="6"<?=($d1=="6")?"checked":""; ?>>
<span class="regular12">ระดับ7</span>
<input name="d1" type="radio" value="7"<?=($d1=="7")?"checked":""; ?>>
<span class="regular12">ระดับ8</span>
<input name="d1" type="radio" value="8"<?=($d1=="8")?"checked":""; ?>></td>
</tr>
<tr>
<td colspan="3" bgcolor="#E8FFE8"><select name="secur_name" id="secur_name">
<option value="<? echo"$secur_name"; ?>" selected><? echo"$secur_name"; ?></option>
<?
$sql="select * from $tbldanger ";
$result=mysql_query($sql);
while($fetch=mysql_fetch_array($result)){
?>
<option value="<?=$fetch['danger_name']?>"><?=$fetch['danger_name']?></option>
<? } ?>
</select> </td>
<td colspan="3" bgcolor="#E8FFE8"><select name="danger_name" id="danger_name">
<option value="<? echo "$danger_name";?>" selected><? echo "$danger_name";?></option>
<?
$sql="select * from $tblsecur ";
$result=mysql_query($sql);
while($fetch=mysql_fetch_array($result)){
?>
<option value="<?=$fetch['secur_name']?>"><?=$fetch['secur_name']?></option>
<? } ?>
</select></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><span class="regular12"> <div align="right"><span class="regular12">วิเคราะห์สาเหตุและที่มา<br>
</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><textarea name="analyzing" cols="40" rows="4" id="analyzing"><?php echo "$analyzing"?></textarea></td>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">ข้อเสนอแนะสำหรับ
การป้องกัน</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><textarea name="suggestion" cols="40" rows="4" id="suggestion"><?php echo "$suggestion"?></textarea></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><span class="regular12">
<div align="right">การสั่งการหรือความ<br>
เห็นของฝ่ายบริหาร</div></td>
<td colspan="3" bgcolor="#E8FFE8"><textarea name="comment" cols="40" rows="4" id="comment"><?php echo "$comment"?></textarea></td>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">ชื่อผู้สั่งการ</span></div></td>
<td width="75" bgcolor="#E8FFE8"><label>
<input name="p_pname" type="text" id="p_pname" value="<?php echo "$p_pname"?>" size="8" />
</label></td>
<td width="43" bgcolor="#E8FFE8"><span class="regular12">นามสุกล</span></td>
<td width="218" bgcolor="#E8FFE8"><input name="p_sname" type="text" id="p_sname" value="<?php echo "$p_sname"?>" size="12"></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">วันที่สั่งการ</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><label>
<input name="p_date" type=text id="p_date" onKeyPress="kod_pum()" size="12" value="<?
list($year, $month, $day) = split('[/.-]', $p_date);
$year = $year + 543;
$p_date= "$day/$month/$year";
echo "$p_date"; ?>">
<script language='javascript'>
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this,\"p_date\", \"dd/mm/yyyy\")' value=' Date ' style='font-size:11px'>")
}
</script>
</label></td>
<td bgcolor="#E8FFE8" class="regular12"> </td>
<td colspan="3" bgcolor="#E8FFE8"><label></label></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">ชื่อผู้ตรวจสอบและรายงาน</span></div></td>
<td bgcolor="#E8FFE8"><input name="aut_pname" type="text" id="aut_pname" value="<?php echo "$aut_pname"?>" size="8" /></td>
<td bgcolor="#E8FFE8"><span class="regular12">นามสกุล</span></td>
<td bgcolor="#E8FFE8"><input name="aut_sname" type="text" id="aut_sname" value="<?php echo "$aut_sname"?>" size="12"></td>
<td bgcolor="#E8FFE8"><div align="right" class="regular12">ภาพความไม่ปลอดภัย </div></td>
<td colspan="3" bgcolor="#E8FFE8"><input name="pic" type="file" id="pic" size="15" /></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">เลขทะเบียน จป.รพ</span></div></td>
<td bgcolor="#E8FFE8"><input name="registration" type="text" id="registration" value="<?php echo "$registration"?>" size="8" /></td>
<td bgcolor="#E8FFE8"><span class="regular12">สถานะ</span></td>
<td bgcolor="#E8FFE8"> </td>
<td bgcolor="#E8FFE8"><div align="right"><span class="regular12">วันที่ตรวจสอบรายงาน</span></div></td>
<td colspan="3" bgcolor="#E8FFE8"><input name="aut_date" type=text class="unnamed1" id="aut_date" onKeyPress="kod_pum()" value="<?
list($year, $month, $day) = split('[/.-]', $aut_date);
$year = $year + 543;
$aut_date= "$day/$month/$year";
echo"$aut_date"; ?>" size="12">
<script language='javascript'>
if (!document.layers) {
document.write("<input type=button onclick='popUpCalendar(this,\"aut_date\", \"dd/mm/yyyy\")' value=' Date ' style='font-size:11px'>")
}
</script>
</td>
</tr>
<tr>
<td bgcolor="#E8FFE8"> </td>
<td width="76" bgcolor="#E8FFE8"><label></label></td>
<td width="46" bgcolor="#E8FFE8"> </td>
<td width="122" bgcolor="#E8FFE8"> </td>
<td bgcolor="#E8FFE8"> </td>
<td colspan="3" bgcolor="#E8FFE8"><label>
</label></td>
</tr>
<tr>
<td bgcolor="#E8FFE8"> </td>
<td colspan="3" bgcolor="#E8FFE8"><div align="right">
<label>
<input name="hdpic" type="hidden" id="hdpic" value="<? echo"$pic";?>">
<input name="Submit" type="submit" value=" แก้ไขข้อมูล " />
</label>
</div></td>
<td bgcolor="#E8FFE8"><label>
<input name="Submit2" type="reset" value=" ยกเลิกแก้ไข " />
</label></td>
<td colspan="3" bgcolor="#E8FFE8" class="regular12"> </td>
</tr>
</table>
</form> </td>
<td bgcolor="#41A72A"></td>
</tr>
<tr>
<td colspan="5">
<img src="images/index_12.jpg" width="968" height="66" alt=""></td>
</tr>
<tr>
<td>
<img src="images/spacer.gif" width="6" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="24" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="184" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="750" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="4" height="1" alt=""></td>
</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
ช่วยหน่อยครับ
Tag : PHP
|
|
|
|
|
|
Date :
2012-07-09 16:09:55 |
By :
มือใหม่ |
View :
1480 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เชค ID ที่ $_GET["id"] หรือยังค่ะ ว่ามันรับค่ามาถูกต้องหรือป่าว
|
|
|
|
|
Date :
2012-07-09 16:19:34 |
By :
OaLunla |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เดี๋ยวผมลองเช็ดดุก่อนนะครับ
|
|
|
|
|
Date :
2012-07-09 16:26:19 |
By :
มือใหม่ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไม่ได้เลยครับ ช่วยหน่อยครับ
|
|
|
|
|
Date :
2012-07-10 07:59:57 |
By :
มือใหม่ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง echo $sql ออกมาเลยค่ะ ว่าคำสั่งมันถูกต้องหรือป่าว แล้วก็ลองนำคำสั่งไปใส่ใน phpmyadmin แล้วก็ลองดูผลลัพธ์น่ะค่ะ
|
|
|
|
|
Date :
2012-07-10 08:38:16 |
By :
OaLunla |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
where '$id' = '".$_GET["id"]."'";
ผิดครับ
where id = '".$_GET["id"]."'";
|
|
|
|
|
Date :
2012-07-10 10:07:21 |
By :
joesimikung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ ขอบคุณ Oa และ joesimikung มาก
where '$id' = '".$_GET["id"]."'"; ผิดครับ
แก้เป็น where id = '".$_GET["id"]."'";
ถามต่ออีกนิดนึงครับ รูปภาพที่ผมแก้ไข แก้ไขได้ แต่ภาพเดิมที่ถูกแก้ไข มันไม่ลบภาพเดิมออกครับ คือมันไม่ไปแทนภาพเดิม มันกลายเป็น
เพิ่มรูปภาพขึ้นเรื่อยครับ ทำให้มันเปลืองพื้นที่นะครับ
ผมใช้ <input name="hdpic" type="hidden" id="hdpic" value="<? echo"$pic";?>">
field ภาพชื่อ pic ครับ
|
|
|
|
|
Date :
2012-07-10 10:31:59 |
By :
มือใหม่ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|