|
|
|
ขอถามเรื่องการแก้ไขข้อมูลในฐานข้อมูลหน่อยครับ ทำไงมันก็ไม่เปลี่ยนให้ |
|
|
|
|
|
|
|
<?php
session_start();
include("Include/connectdb.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>Action Register</title>
<link rel = "stylesheet" type = "text/css" href = "css/style.css" />
</head>
<body>
<div id = "wrapper">
<?php
if($_REQUEST['Do'] == "register")
{
$stu_id = $_REQUEST['stu_id'];
$pass_1 = sha1($_REQUEST['pass_1']);
$pass_2 = sha1($_REQUEST['pass_2']);
$fname = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
$sex = $_REQUEST['sex'];
$email = $_REQUEST['email'];
$edu = $_REQUEST['ddleducation'];
$fac = $_REQUEST['ddlfaculty'];
$bra = $_REQUEST['ddlbranch'];
$edu1 = $_REQUEST['ddleducation1'];
$fac1 = $_REQUEST['ddlfaculty1'];
$bra1 = $_REQUEST['ddlbranch1'];
$edu2 = $_REQUEST['ddleducation2'];
$fac2 = $_REQUEST['ddlfaculty2'];
$bra2 = $_REQUEST['ddlbranch2'];
$e = array($edu,$edu1,$edu2);
$f = array($fac,$fac1,$fac2);
$b = array($bra,$bra1,$bra2);
$photo = $_FILES['photo']['tmp_name'];
$photo_name = $_FILES['photo']['name'];
$photo_size = $_FILES['photo']['size'];
$photo_type = $_FILES['photo']['type'];
if(trim($stu_id) == "" || trim($pass_1) == "" || trim($pass_2) == "" || trim($email) == "" || trim($fname) == "" || trim($lname) == "")
{
echo "<p class ='showtxt'>คุณยังกรอกข้อมูลไม่ครบ กรูณากรอกข้อมูลให้ครบ</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=register' />";
exit();
}
else if($pass_1 != $pass_2)
{
echo "<p class ='showtxt'>รหัสผ่านไม่ตรงกัน</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=register' />";
exit();
}
else if($edu == 0 && $edu1 == 0 && $edu2 == 0)
{
echo "<p class ='showtxt'>คุณต้องเลือกระดับการศึกษาอย่างน้อย 1 ระดับการศึกษา</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=register' />";
exit();
}
else if($fac == 0 && $fac1 == 0 && $fac2 == 0)
{
echo "<p class ='showtxt'>คุณยังไม่ได้เลือกสาขา</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=register' />";
exit();
}
else
{
$sql = "select * from member where stu_id = '$stu_id' or email = '$email';";
$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);
if($num > 0)
{
echo "<p class ='showtxt'>มีรหัสนักศึกษา หรือ E-mail อยู่ในฐานข้อมูลแล้ว</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=register' />";
exit();
}
else if(trim($photo) == "")
{
$male = "male.png";
$female = "female.png";
if($sex == "m")
{
$sql = "insert into member(stu_id,pass,email,fname,lname,sex,photo) values('$stu_id','$pass_1','$email','$fname','$lname','$sex','$male');";
$result = mysql_query($sql) or die (mysql_error());
}
else if($sex == "f")
{
$sql = "insert into member(stu_id,pass,email,fname,lname,sex,photo) values('$stu_id','$pass_1','$email','$fname','$lname','$sex','$female');";
$result = mysql_query($sql) or die (mysql_error());
}
}
else
{
$set_name = explode(".",$photo_name);
$pfname = "stu_".$stu_id;
$plname = $set_name[1];
$photoname = $pfname.".".$plname;
copy($photo,"photo/".$photoname);
$sql = "insert into member(stu_id,pass,email,fname,lname,sex,photo) values('$stu_id','$pass_1','$email','$fname','$lname','$sex','$photoname');";
$result = mysql_query($sql) or die (mysql_error());
}
}
$i = 0;
while($e[$i] != 0 && $i < 3)
{
if($f[$i] != 0)
{
$sql = "insert into study(ref_stu_id,ref_edu_id,ref_fac_id,ref_bra_id) values('$stu_id','$e[$i]','$f[$i]','$b[$i]');";
$result = mysql_query($sql) or die (mysql_error());
}
$i = $i + 1;
}
if($result)
{
echo "<p class ='showtxt'>บันทึกข้อมูลเรียบร้อยแล้ว</p>";
echo "<meta http-equiv ='refresh' content ='2;url=index.php' />";
}
else
{
echo "<p class ='showtxt'>ไม่สามารถบันทึกข้อมูลได้</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=register' />";
}
}
else if($_REQUEST['Do'] == "edit")
{
$stu_id = $_REQUEST['stu_id'];
$fname = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
$sex = $_REQUEST['sex'];
$edu = $_REQUEST['ddleducation'];
$fac = $_REQUEST['ddlfaculty'];
$bra = $_REQUEST['ddlbranch'];
$edu1 = $_REQUEST['ddleducation1'];
$fac1 = $_REQUEST['ddlfaculty1'];
$bra1 = $_REQUEST['ddlbranch1'];
$edu2 = $_REQUEST['ddleducation2'];
$fac2 = $_REQUEST['ddlfaculty2'];
$bra2 = $_REQUEST['ddlbranch2'];
$e = array($edu,$edu1,$edu2);
$f = array($fac,$fac1,$fac2);
$b = array($bra,$bra1,$bra2);
$photo = $_FILES['photo']['tmp_name'];
$photo_name = $_FILES['photo']['name'];
$photo_size = $_FILES['photo']['size'];
$photo_type = $_FILES['photo']['type'];
if(trim($fname) == "" || trim($lname) == "")
{
echo "<p class ='showtxt'>คุณยังกรอกข้อมูลไม่ครบ กรูณากรอกข้อมูลให้ครบ</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=edit_profile' />";
exit();
}
else if($edu == 0 && $edu1 == 0 && $edu2 == 0)
{
echo "<p class ='showtxt'>คุณต้องเลือกระดับการศึกษาอย่างน้อย 1 ระดับการศึกษา</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=edit_profile' />";
exit();
}
else if($fac == 0 && $fac1 == 0 && $fac2 == 0)
{
echo "<p class ='showtxt'>คุณยังไม่ได้เลือกสาขา</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=edit_profile' />";
exit();
}
else if(trim($photo) == "")
{
$sql = "select * from member where stu_id = 'stu_id';";
$result = mysql_query($sql) or die (mysql_error());
$dbarr = mysql_fetch_array($result);
$male = "male.png";
$female = "female.png";
if($sex == "m")
{
if($dbarr['photo'] == $female)
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' , photo = '$male' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
else
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
}
else if($sex == "f")
{
if($dbarr['photo'] == $male)
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' , photo = '$female' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
else
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
}
$sql = "delete from study where ref_stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
else
{
$set_name = explode(".",$photo_name);
$pfname = "stu_".$stu_id;
$plname = $set_name[1];
$photoname = $pfname.".gif";
@unlink("photo/$photoname");
copy($photo,"photo/".$photoname);
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' , photo = '$photoname' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
$sql = "delete from study where ref_stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
$i = 0;
while($e[$i] != 0 && $i < 3)
{
if($f[$i] != 0)
{
$sql = "insert into study(ref_stu_id,ref_edu_id,ref_fac_id,ref_bra_id) values('$stu_id','$e[$i]','$f[$i]','$b[$i]');";
$result = mysql_query($sql) or die (mysql_error());
}
$i = $i + 1;
}
if($result)
{
echo "<p class ='showtxt'>บันทึกข้อมูลเรียบร้อยแล้ว</p>";
echo "<meta http-equiv ='refresh' content ='2;url=index.php' />";
}
else
{
echo "<p class ='showtxt'>ไม่สามารถบันทึกข้อมูลได้</p>";
echo "<meta http-equiv ='refresh' content ='2;url=action_member.php?ToDo=edit_profile' />";
}
}
?>
</div>
</body>
</html>
<?php
include("Include/closedb.php");
?>
มีปัญหาตรงนี้ ครับ
else if(trim($photo) == "")
{
$sql = "select * from member where stu_id = 'stu_id';";
$result = mysql_query($sql) or die (mysql_error());
$dbarr = mysql_fetch_array($result);
$male = "male.png";
$female = "female.png";
if($sex == "m")
{
if($dbarr['photo'] == $female)
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' , photo = '$male' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
else
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
}
else if($sex == "f")
{
if($dbarr['photo'] == $male)
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' , photo = '$female' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
else
{
$sql = "update member set fname = '$fname', lname = '$lname', sex = '$sex' where stu_id = '$stu_id';";
$result = mysql_query($sql) or die (mysql_error());
}
}
ขั้นตอนการทำงานนะครับ เป็นการเปลี่ยนแปลง ข้อมูลของสมาชิกครับ โดยจะข้ามมาที่การตรวจสอบรูปภาพ ถ้าไม่มีการส่งรูปภาพมา แต่มีการเปลี่ยนเพศ รูปจะเปลี่ยนไป ตามเพศที่เลือก แต่ปัญหาคือ ทุก feild ที่เปลี่ยนแปลง จะมีการแก้ไขในฐานข้อมูลทั้งหมด ยกเว้น feild ของ photo ครับ มันเกิดไรขี้นวอนแนะนำหน่อยครับ
Tag : PHP, HTML/CSS
|
ประวัติการแก้ไข 2012-11-18 12:12:59
|
|
|
|
|
Date :
2012-11-18 12:11:39 |
By :
sompon01 |
View :
1010 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมผิดเองครับ เจอปัญหาแล้วครับ
$sql = "select * from member where stu_id = '$stu_id';";
|
|
|
|
|
Date :
2012-11-18 12:53:52 |
By :
sompon01 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2012-11-18 13:16:56 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|