|
 |
|
สร้างฟอร์มบันทึกข่าวประชาสัมพันธ์ เวลาบันทึกเราจะเลือกแนบไฟล์ด้วย หรือไม่ต้องแนบไฟล์ ก็ได้ทำยังไงคับ มีภาพให้ดู |
|
 |
|
|
 |
 |
|

ดังรูปเลยคับ พอดีผมทำระบบบันทึกข่าวสารคับ เวลาลงประกาศข่าวสาร
บางครั้งก็ต้องมีแนบไฟล์ หรือบางครั้งข่าวก็ไม่มีไฟล์ แต่พอดีผมทำ มันต้องกรอกข้อมูลให้ครบและต้องแนบไฟล์
ทุกครั้งถึงจะบันทึกผ่าน ผมอยากให้บันทึกข่าวแล้วจะุแนบไฟล์ด้วย หรือไม่แนบก็ได้คับ
นี่โค๊ด บันทึกผม
Code (PHP)
<?
$fileName = date("YmdHis")."_".$_FILES["filUpload"]["name"];
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],$path="oprnewsfiles/".$_FILES["filUpload"]["name"]))
// if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],$path="filesnews/".$fileName))
{
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("personnel_db");
mysql_query("SET NAMES UTF8");
mysql_query("SET character_set_results=tis620",$objConnect);
mysql_query("SET character_set_client='tis620'",$objConnect);
mysql_query("SET character_set_connection='tis620'",$objConnect);
mysql_query("collation_connection = tis620_thai_ci",$objConnect);
mysql_query("collation_database = tis620_thai_ci",$objConnect);
mysql_query("collation_server = tis620_thai_ci",$objConnect);
$date_in = date("d-m-Y");
$strSQL = "INSERT INTO t_oprnews ";
$strSQL .="(id_oprnews,oprnews_act,oprnews_detail,oprnews_files,oprnews_date,oprnews_datein,oprnews_user) ";
$strSQL .="VALUES ";
$strSQL .="('','".$_POST["news"]."','".$_POST["opr_news"]."','".$_FILES["filUpload"]["name"]."','".$_POST["date_news"]."','$date_in','".$_POST["useract"]."') ";
$objQuery = mysql_query($strSQL);
mysql_close($objConnect);
echo "บันทึกข่าวประชาสัมพันธ์เรียบร้อยแล้วคับ<br>";
echo "<meta http-equiv=refresh content=1;URL=admin.php>";
}
else
{
echo "Error Save [".$strSQL."]";
echo "<meta http-equiv=refresh content=1;URL=addnewsopr.php>";
}
?>
Tag : PHP, JavaScript

|
|
 |
 |
 |
 |
Date :
2012-04-25 10:24:43 |
By :
compiak |
View :
3214 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ต้องดูว่า oprnews_files ที่ mysql กำหนดเป็น null หรือ not null ครับ
|
 |
 |
 |
 |
Date :
2012-04-25 10:38:20 |
By :
time.toon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมก็กำหนดให้ เป็น null แล้วนะ
ผมว่าต้องผิดที่โค๊ดแน่ๆ
|
 |
 |
 |
 |
Date :
2012-04-25 12:59:53 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
eror save []
|
 |
 |
 |
 |
Date :
2012-04-25 16:30:53 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณครับ โค๊ดผิดนิดหน่อย
แก้ไขเป็น
Code (PHP)
<?
// $fileName = date("YmdHis")."_".$_FILES["filUpload"]["name"];
// if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],$path="oprnewsfiles/".$_FILES["filUpload"]["name"]))
// if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],$path="filesnews/".$fileName))
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("personnel_db");
mysql_query("SET NAMES UTF8");
mysql_query("SET character_set_results=tis620",$objConnect);
mysql_query("SET character_set_client='tis620'",$objConnect);
mysql_query("SET character_set_connection='tis620'",$objConnect);
mysql_query("collation_connection = tis620_thai_ci",$objConnect);
mysql_query("collation_database = tis620_thai_ci",$objConnect);
mysql_query("collation_server = tis620_thai_ci",$objConnect);
move_uploaded_file($_FILES["filUpload"]["tmp_name"],$path="oprnewsfiles/".$_FILES["filUpload"]["name"]);
$date_in = date("d-m-Y");
$strSQL = "INSERT INTO t_oprnews ";
$strSQL .="(id_oprnews,oprnews_act,oprnews_detail,oprnews_files,oprnews_date,oprnews_datein,oprnews_user) ";
$strSQL .="VALUES ";
$strSQL .="('','".$_POST["news"]."','".$_POST["opr_news"]."','".$_FILES["filUpload"]["name"]."','".$_POST["date_news"]."','$date_in','".$_POST["useract"]."') ";
$objQuery = mysql_query($strSQL);
mysql_close($objConnect);
echo "บันทึกข่าวประชาสัมพันธ์เรียบร้อยแล้วคับ<br>";
echo "<meta http-equiv=refresh content=1;URL=admin.php>";
?>
|
 |
 |
 |
 |
Date :
2012-04-25 16:44:58 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|