|
 |
|
รบกวนช่วยดู Code ผมด้วยครับ เกี่ยวกับ บันทึกข้อมูลหลายเงื่อนไข |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
session_start();
?>
<!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>::บันทึกข้อมูล Schedule::</title>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="800">
<tr>
<td>
<?php
include "header.html";
?>
</td>
</tr>
<tr>
<td width="700" height="400" align="center" valign="middle">
<?php
$Id_Emp=$_SESSION["user"];
$Id_Dept=$_REQUEST["id_dept"];
$Id_Company=$_REQUEST["company"];
$FileName=$_FILES["file"]["name"];
$strCheck=$_REQUEST["strCaptcha"];
$Wantee=date("d-m-Y");
/*------------------------------------------------Echo Variable------------------------------------------------------------------
echo $Id_Company;
echo $Id_Dept;
echo $strCheck;
echo $FileName;
--------------------------------------------------------------------------------------------------------------------------------*/
?>
<table align="center">
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
/*------------------------------Check Variable == NULL--------------------------------------------------------------*/
if($Id_Company=="" || $FileName=="" || $strCheck==""){
echo "ท่านกรอกข้อมูลไม่ครบ กรุณากรอกข้อมูลให้ครบค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<?php
/*-------------------------------------End----------------------------------------------------------------------------------------*/
?>
<?php
}else{
?>
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
if($_SESSION[MyKey]!==$strCheck){
echo "โค้ดของท่านไม่ถูกต้องค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<?php
}else{
?>
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
include "../connect.php";
mysql_query("SET NAMES UTF8");
$SQL_Obj="SELECT * FROM files WHERE Files_Name='$FileName'";
$ObjQuery=mysql_query($SQL_Obj)or die ("Error Query [".$SQL_Obj."]");
$ResultRow=mysql_num_rows($ObjQuery);
if($ResultRow>0){
echo "ไฟล์ที่ท่านอัพโหลดมีอยู่แล้ว กรุณาอัพโหลดไฟล์ใหม่ค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<?php
/*-------------------------------------------------End----------------------------------------------------------------------*/
?>
<?php
}else{
?>
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
if($_FILES["file"]["size"] > 5000000){
echo "ขนาดไฟล์ใหญ่เิกินไป กรุณาอัพโหลดไฟล์ใหม่ค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<?php
}else{
?>
<?php
/*-----------------------Insert Record------------------------------------------------------------------------*/
?>
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
if($Id_Dept=='1'){
include "../connect.php";
mysql_query("SET NAMES UTF8");
(copy($_FILES["file"]["tmp_name"],"../Schedule/ScheduleImport".$_FILES["file"]["name"]));
$SQL_INSERT="INSERT INTO files(Id_Emp, Id_Company, Id_Dept, Files_Name, Wantee)
VALUES('".$Id_Emp."', '".$Id_Company."', '".$Id_Dept."', '".$_FILES["file"]["name"]."', '".$Wantee."')";
$ObjQuery = mysql_query($SQL_INSERT)or die ("Error Query [".$SQL_INSERT."]");
if($ObjQuery){
echo "กำลังบันทึกข้อมูลค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
}else{
if($Id_Dept=='2'){
include "../connect.php";
mysql_query("SET NAMES UTF8");
(copy($_FILES["file"]["tmp_name"],"../Schedule/ScheduleExport".$_FILES["file"]["name"]));
$SQL_INSERT="INSERT INTO files(Id_Emp, Id_Company, Id_Dept, Files_Name, Wantee)
VALUES('".$Id_Emp."', '".$Id_Company."', '".$Id_Dept."',
'".$_FILES["file"]["name"]."', '".$Wantee."')";
$ObjQuery = mysql_query($SQL_INSERT)or die ("Error Query [".$SQL_INSERT."]");
if($ObjQuery){
echo "กำลังบันทึกข้อมูลค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<?php
}else{
?>
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
echo"ไม่สามารถบันทึกข้อมูลได้ กรุณาตรวจสอบข้อมูลด้วยค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
<?php
}
}
}
}
}
}
}
}
?>
</table>
</td>
</tr>
<tr>
<td>
<?php
include "footer.html";
?>
</td>
</tr>
</table>
</body>
</html>
Cdoe ไม่มี Error ครับผม แต่ ไม่เข้าสู่การ บันทึกข้อมูลครับ
ผมสงสัยว่า เอ่ หรือ ผม จะเขียน ผิด รูปแบบ การ บันทึกข้อมูลแบบ หลายเงื่อนไข หรือ เปล่า ยังไง
รบกวน พี่ๆ เก่งๆ ช่วย ชี้แนะด้วยนะครับผม
ขอบคุณล่วงหน้าครับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2010-11-25 11:24:21 |
By :
popnakub |
View :
756 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง echo $SQL_INSERT ดูครับว่ามีค่าอะไร
|
 |
 |
 |
 |
Date :
2010-11-25 11:38:22 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มเติมนะครับ
เงื่อนไขแรกออก นะ ครับ
แต่เงื่อนไขที่2ไม่ออกครับ -*- เด๋วผมจะลอง echo sql ออก มา ดู ก่อนครับ ได้ ความว่ายังไงจะมาแจ้งอีกทีครับ
|
 |
 |
 |
 |
Date :
2010-11-25 11:43:54 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เงื่อนไข
$Id_Dept==1 บันทึกได้ครับ echo ค่า ออก มา หมด ครับ
พอ จะ ให้ข้อมูลมาเข้า เงื่อนไขที่ 2 เหมือนกับ ว่า ข้อมูล มัน ไม่เข้า เงื่อนไข ครับ
พอ echo ค่า ออก มา แล้ว ว่าง เปล่าครับ
หรือ เป็น เพราะ ว่า ผม ใช้ Condition ผิด ที่ ผม ใช้ If...Else หรือ ผม ควรใช้ if...ifelse....else ครับ
รบกวนช่วยชี้ แนะ ด้วย นะ ครับ ผม
|
 |
 |
 |
 |
Date :
2010-11-25 11:53:11 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
187 ครับ ลบออกเลย จาก code ที่ไหนมา แล้วการเขียนถ้าไม่อยู่ในเท็ก php ไม่ต้องเขียนแบบนั้นครับ ถ้าเป็นแบบที่คุณเขียนน่ะมัน ไม่เข้า else เหรกครับ ให้ if ใหม่เลยครับ
|
 |
 |
 |
 |
Date :
2010-11-25 12:59:42 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้ เหมือน เดิม ครับผม
ยังไง ก็ขอบคุณมากนะครับ
ไง เด๋ว จะ ลอง หา วิธี อื่น ดู ครับ
|
 |
 |
 |
 |
Date :
2010-11-25 13:53:57 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
session_start();
?>
<!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>::บันทึก Schedule::</title>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="800">
<tr>
<td>
<?php
include "header.html";
?>
</td>
</tr>
<tr>
<td width="700" height="400" align="center" valign="middle">
<table align="center">
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
$Id_Emp=$_SESSION["user"];
$Id_Dept=$_REQUEST["id_dept"];
$Id_Company=$_REQUEST["company"];
$FileName=$_FILES["file"]["name"];
$strCheck=$_REQUEST["strCaptcha"];
$Wantee=date("d-m-Y");
/*------------------------------------------------Echo Variable------------------------------------------------------------------
echo $Id_Company;
echo $Id_Dept;
echo $strCheck;
echo $FileName;
-------------------------------------------------------------------------------------------*/
/*------------------------------Check Variable == NULL-----------------------------------*/
if($Id_Company=="" || $FileName=="" || $strCheck==""){
echo "ท่านกรอกข้อมูลไม่ครบ กรุณากรอกข้อมูลให้ครบค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
/*-------------------------------------End-----------------------------------------------*/
}else{
if($_SESSION[MyKey]!==$strCheck){
echo "โค้ดของท่านไม่ถูกต้องค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}else{
include "../connect.php";
mysql_query("SET NAMES UTF8");
$SQL_Obj="SELECT * FROM files WHERE Files_Name='$FileName'";
$ObjQuery=mysql_query($SQL_Obj)or die ("Error Query [".$SQL_Obj."]");
$ResultRow=mysql_num_rows($ObjQuery);
if($ResultRow>0){
echo "ไฟล์ที่ท่านอัพโหลดมีอยู่แล้ว กรุณาอัพโหลดไฟล์ใหม่ค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}else{
if($_FILES["file"]["size"] > 5000000){
echo "ขนาดไฟล์ใหญ่เิกินไป กรุณาอัพโหลดไฟล์ใหม่ค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}else{
include "../connect.php";
mysql_query("SET NAMES UTF8");
if($Id_Dept==1){ //ส่วนที่เปลี่ยนครับ
(copy($_FILES["file"]["tmp_name"],"../Schedule/ScheduleImport/".$_FILES["file"]["name"]));
}else{
(copy($_FILES["file"]["tmp_name"],"../Schedule/ScheduleExport/".$_FILES["file"]["name"]));
}
$SQL_INSERT="INSERT INTO files(Id_Emp, Id_Company, Id_Dept, Files_Name, Wantee)
VALUES('".$Id_Emp."', '".$Id_Company."', '".$Id_Dept."', '".$_FILES["file"]["name"]."', '".$Wantee."')";
$ObjQuery = mysql_query($SQL_INSERT)or die ("Error Query [".$SQL_INSERT."]");
if($ObjQuery){
echo "กำลังบันทึกข้อมูลค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}else{
echo"ไม่สามารถบันทึกข้อมูลได้ กรุณาตรวจสอบข้อมูลด้วยค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
?>
</font>
</td>
</tr>
<?php
}
}
}
}
}
?>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
include "footer.html";
?>
</td>
</tr>
</table>
</body>
</html>
ได้แล้วครับผม แต่ไม่รู้ว่าจะมีปัญหาหรือไม่ ยังไงก็ช่วย แนะนำ เพิ่ม เติม ด้วยนะคร๊าฟ
|
 |
 |
 |
 |
Date :
2010-11-25 15:40:55 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้ามีก็การเช็ค if else ของคุณนั้นแหลครับ มันแปลกยังไงไม่รู้
|
 |
 |
 |
 |
Date :
2010-11-25 15:56:45 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
session_start();
?>
<!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>::บันทึก Schedule::</title>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="800">
<tr>
<td>
<?php
include "header.html";
?>
</td>
</tr>
<tr>
<td width="700" height="400" align="center" valign="middle">
<table align="center">
<tr>
<td align="center">
<font face="sans-serif" size="2">
<?php
$Id_Emp=$_SESSION["user"];
$Id_Dept=$_REQUEST["id_dept"];
$Id_Company=$_REQUEST["company"];
$FileName=$_FILES["file"]["name"];
$strCheck=$_REQUEST["strCaptcha"];
$Wantee=date("d-m-Y");
/*------------------------------------------------Echo Variable------------------
echo $Id_Company;
echo $Id_Dept;
echo $strCheck;
echo $FileName;
-------------------------------------------------------------------------------------------*/
/*------------------------------Check Variable == NULL-----------------------------------*/
if($Id_Company=="" || $FileName=="" || $strCheck==""){
echo "ท่านกรอกข้อมูลไม่ครบ กรุณากรอกข้อมูลให้ครบค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
/*-------------------------------------End-----------------------------------------------*/
}elseif($_SESSION[MyKey]!==$strCheck){
echo "โค้ดของท่านไม่ถูกต้องค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}elseif($_FILES["file"]["size"] > 5000000){
echo "ขนาดไฟล์ใหญ่เิกินไป กรุณาอัพโหลดไฟล์ใหม่ค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}else{
include "../connect.php";
mysql_query("SET NAMES UTF8");
$SQL_Obj="SELECT * FROM files WHERE Files_Name='$FileName'";
$ObjQuery=mysql_query($SQL_Obj)or die ("Error Query [".$SQL_Obj."]");
$ResultRow=mysql_num_rows($ObjQuery);
if($ResultRow>0){
echo "ไฟล์ที่ท่านอัพโหลดมีอยู่แล้ว กรุณาอัพโหลดไฟล์ใหม่ค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}
if($Id_Dept==1){
(copy($_FILES["file"]["tmp_name"],"../Schedule/ScheduleImport/".$_FILES["file"]["name"]));
}elseif($Id_Dept==2){
(copy($_FILES["file"]["tmp_name"],"../Schedule/ScheduleExport/".$_FILES["file"]["name"]));
}
include "../connect.php";
mysql_query("SET NAMES UTF8");
$SQL_INSERT="INSERT INTO files(Id_Emp, Id_Company, Id_Dept, Files_Name, Wantee)
VALUES('".$Id_Emp."', '".$Id_Company."', '".$Id_Dept."', '".$_FILES["file"]["name"]."', '".$Wantee."')";
$ObjQuery = mysql_query($SQL_INSERT)or die ("Error Query [".$SQL_INSERT."]");
if($ObjQuery){
echo "กำลังบันทึกข้อมูลค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}else{
echo"ไม่สามารถบันทึกข้อมูลได้ กรุณาตรวจสอบข้อมูลด้วยค่ะ <META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;URL=frm_add_schedule.php\">";
}
}
?>
</font>
</td>
</tr>
<tr>
<td align="center">
<img src="../Image/admin/loading.gif" border="0" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
include "footer.html";
?>
</td>
</tr>
</table>
</body>
</html>
ลองจัดใหม่ แล้วครับ ก็ น่า จะ ไม่ แปลก เท่าไหร่ นะ ครับ
|
 |
 |
 |
 |
Date :
2010-11-25 16:37:51 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไงก็ ขอบคุณทุกๆคำตอบนะครับผม ยังไง เด๋ว ผม จะ มา เพิ่ม คะแนนให้ นะ ครับ
|
 |
 |
 |
 |
Date :
2010-11-25 16:39:40 |
By :
popnakub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|