|
|
|
ตรวจสอบค่าว่างก่อนทำการโพสหรืออัพโหลดขอ้มูลผมต้อง แทรก code ตรงไหนครับ |
|
|
|
|
|
|
|
Code (PHP)
<?
include("conection2.php");
include("function.php");
CheckSession();
foreach($_POST as $key => $value) {
$value=mysql_real_escape_string($value);
//echo $key."/".$value."</br>";
}
//$return_to_page="../articles.php";
$return_to_page="../articles_list.php?";
if($_POST["METHOD"]=="remove_ban"){
if(unlink($_POST["IMAGE_REMOVE"])){ //DELETE IMG***********************************************************
update_pic("","BANNER",$_POST["txtARTICLES_ID"]);
}
echo "<form action='".$return_to_page."' method='post' name='frm'>";
echo '<input name="txtCATEGORY" type="hidden" id="txtCATEGORY" value="'.$_POST["txtCATEGORY"].'" />';
echo '<input name="edit_id" type="hidden" id="edit_id" value="'.$_POST["txtARTICLES_ID"].'" />';
echo "</form>";
}elseif($_POST["METHOD"]=="remove_img"){
if(unlink($_POST["IMAGE_REMOVE"])){ //DELETE IMG***********************************************************
update_pic("","IMAGE",$_POST["txtARTICLES_ID"]);
}
echo "<form action='".$return_to_page."' method='post' name='frm'>";
echo '<input name="txtCATEGORY" type="hidden" id="txtCATEGORY" value="'.$_POST["txtCATEGORY"].'" />';
echo '<input name="edit_id" type="hidden" id="edit_id" value="'.$_POST["txtARTICLES_ID"].'" />';
echo "</form>";
}elseif(trim($_POST["txtARTICLES_ID"])!=""){
$sql=" UPDATE tb_articles ";
$sql.=" SET TITLE = '".$_POST["txtTitle"]."',";
$sql.=" PROVINCE = '".$_POST["txtPROVINCE"]."',";
$sql.=" HILINGHT = '".$_POST["chkHilight"]."',";
$sql.=" `DESC` = '".$_POST["editor1"]."'";
$sql.=" WHERE ARTICLES_ID =".$_POST["txtARTICLES_ID"]." LIMIT 1 ;";
$rs = mysql_query($sql);
$sql="";
//Upload***********************************************************
//if($_FILES["ImageUpload"]["tmp_name"]!=""){
$Banner=GenName_Pic($_FILES["BannerUpload"],"BANNER",$_POST["txtARTICLES_ID"]);
if(copy($_FILES["BannerUpload"]["tmp_name"],$img_path.$Banner) )
{
update_pic($Banner,"BANNER",$_POST["txtARTICLES_ID"]);
}
//}
//if($_FILES["ImageUpload"]["tmp_name"]!=" "){
$img=GenName_Pic($_FILES["ImageUpload"],"IMG",$_POST["txtARTICLES_ID"]);
if(copy($_FILES["ImageUpload"]["tmp_name"],$img_path.$img ))
{
update_pic($img,"IMAGE",$_POST["txtARTICLES_ID"]);
}
//}
//Upload***********************************************************
echo "<form action='".$return_to_page."' method='post' name='frm'>";
echo '<input name="txtCATEGORY" type="hidden" id="txtCATEGORY" value="'.$_POST["txtCATEGORY"].'" />';
echo '<input name="edit_id" type="hidden" id="edit_id" value="'.$_POST["txtARTICLES_ID"].'" />';
echo "</form>";
}elseif(trim($_POST["txtTitle"])!=""){
$sql="INSERT INTO tb_articles (";
$sql.=" ARTICLES_ID ,";
$sql.=" CATEGORY ,";
$sql.=" TITLE ,";
$sql.=" PROVINCE ," ;
$sql.=" HILINGHT ,";
$sql.=" `DESC` ,";
$sql.=" `ACTIVE` ," ;
$sql.=" INACTIVE ,";
$sql.=" CREATE_DT";
$sql.=" )VALUES(";
$sql.=" NULL ,";
$sql.=" '".$_POST["txtCATEGORY"]."',";
$sql.=" '".$_POST["txtTitle"]."',";
$sql.=" '".$_POST["txtPROVINCE"]."',";
$sql.=" '".$_POST["chkHilight"]."',";
$sql.=" '".$_POST["editor1"]."',";
$sql.=" '1',";
$sql.=" NULL,";
$sql.=" now());";
$rs = mysql_query($sql);
$sql="";
$last_id = mysql_insert_id($db);
$Banner=GenName_Pic($_FILES["BannerUpload"],"BANNER",$last_id);
$img=GenName_Pic($_FILES["ImageUpload"],"IMG",$last_id);
//Upload***********************************************************
if(copy($_FILES["BannerUpload"]["tmp_name"],$img_path.$Banner) )
{
update_pic($Banner,"BANNER",$last_id);
}
if(copy($_FILES["ImageUpload"]["tmp_name"],$img_path.$img ))
{
update_pic($img,"IMAGE",$last_id);
}
//Upload***********************************************************
echo "<form action='".$return_to_page."' method='post' name='frm'>";
echo '<input name="txtCATEGORY" type="hidden" id="txtCATEGORY" value="'.$_POST["txtCATEGORY"].'" />';
echo '<input name="edit_id" type="hidden" id="edit_id" value="'.$last_id.'" />';
echo "</form>";
}
for($i=1;$i<10+1;$i++)
{
json_set_list_News($i);
json_set_list_Event($i);
}
json_set_list_ads();
json_set_list_ads_event();
json_set_list_ads_news();
$direc='<script language="JavaScript">document.frm.submit();</script>';
echo $direc;
mysql_close();
?>
Tag : PHP
|
|
|
|
|
|
Date :
2015-02-25 21:18:34 |
By :
puwanet |
View :
677 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วแต่คนออกแบบครับ ลักษณะที่คุณเขียนสามารถเช็คค่าว่างได้ประมาณนี้
Code (PHP)
...
}elseif(trim($_POST["txtTitle"])!=""){
#เช็คค่าว่างตรงนี้ก็ได้ หรือก่อนหน้านี้
if(#เช็คค่าอะไรบ้างก็ว่าไป){
.....
} else if(...){
....
} else { #เมื่อเช็คค่าว่างทุกค่าเสดแล้วก็ให้บันทึกได้
$sql="INSERT INTO tb_articles (";
$sql.=" ARTICLES_ID ,";
$sql.=" CATEGORY ,";
$sql.=" TITLE ,";
$sql.=" PROVINCE ," ;
$sql.=" HILINGHT ,";
$sql.=" `DESC` ,";
$sql.=" `ACTIVE` ," ;
$sql.=" INACTIVE ,";
$sql.=" CREATE_DT";
$sql.=" )VALUES(";
$sql.=" NULL ,";
$sql.=" '".$_POST["txtCATEGORY"]."',";
$sql.=" '".$_POST["txtTitle"]."',";
$sql.=" '".$_POST["txtPROVINCE"]."',";
$sql.=" '".$_POST["chkHilight"]."',";
$sql.=" '".$_POST["editor1"]."',";
........#คำสั่งอื่นๆ......
}
ปล. อย่าเอาของผมไปทั้งหมดนะ เพราะมันไม่ถูกแน่นอน เอาไปแค่แนวคิดนะครัช
|
|
|
|
|
Date :
2015-02-25 21:32:23 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ข้อสังเกตุ : elseif เขียนติดกันได้หรือเปล่าไม่แน่ใจ เคยใช้แต่ else if ถ้าเขียน elseif อาจไม่เข้าเงื่อนไข หรือเปล่า
|
|
|
|
|
Date :
2015-02-26 08:45:51 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|