|
![](/images/resource/spacer.gif) |
|
ช่วยหน่อยนะคะ - อันนี้เป็นโค้ดหน้าแบบฟอร์มให้กรอกหัวข้อข่าว , รายละเอียดข่าว , browse ภาพ ค่ะ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
อันนี้เป็นโค้ดหน้าแบบฟอร์มให้กรอกหัวข้อข่าว , รายละเอียดข่าว , browse ภาพ ค่ะ
<!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>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>
<script language="javascript">
function checkform()
{
if(form1.title.value=="" )
{
alert ('ยังไม่ได้กรอกหัวข้อข่าว');
form1.title.focus();
return false;
}
else if(form1.des.value=="" )
{
alert ('ยังไม่ได้กรอกหัวข้อข่าว');
form1.des.focus();
return false;
}
}
</script>
<body>
<form id="form1" name="form1" method="post" action="addAnn.php" enctype="multipart/form-data" onsubmit="return checkform();">
<table width="518" border="0" align="center">
<tr>
<td height="34" colspan="2" bgcolor="#000099"><div align="center" class="style1">เพิ่มข่าวประชาสัมพันธ์</div></td>
</tr>
<tr>
<td height="21"> </td>
<td> </td>
</tr>
<tr>
<td width="119" height="27"><strong>หัวข้อข่าว :</strong></td>
<td width="389"><label>
<input name="title" type="text" id="title" size="50" maxlength="50" />
</label></td>
</tr>
<tr>
<td><strong>รายละเอียด :</strong></td>
<td><label>
<textarea name="des" cols="47" rows="10" id="des"></textarea>
</label></td>
</tr>
<tr>
<td><strong>ภาพประกอบ :</strong></td>
<td><label>
<input name="fileUpload" type="file" id="fileUpload" value="" />
</label></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit2" value=" เพิ่ม " />
<input type="reset" name="Submit3" value="ยกเลิก" />
</div>
</div>
</label>
</div></td>
</tr>
</table>
</form>
</body>
</html>
อันนี้เป็นโค้ดของ page addAnn.php ค่ะ
Code (PHP)
<?php
ob_start();
include("connect.php"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?
$title = $_POST["title"];
$des = $_POST["des"];
//$id = $_POST["id"];
$date = date("Y/m/d H:i:s", mktime(date("H"), date("i")+0, date("s")+0, date("m")+0 , date("d")+0, date("Y")+0));
$pic = $_FILES["fileUpload"]["name"];
$sql = "select * from announcement where ann_title ='$title'";
$result = mysql_query($sql) or die("Select error");
$count = mysql_num_rows($result);
if($count > 0)
{
echo "<script>alert('หัวข้อข่าวนี้มีแล้ว');history.back();</script>";
exit();
}
else if(copy($_FILES["fileUpload"]["tmp_name"],"myfile/".$pic))
{
//echo "Copy/Upload Complete<br>";
//*** Insert Record ***//
//$strSQL = "INSERT INTO files ";
//$strSQL .="(FilesName) VALUES ('".$_FILES["filUpload"]["name"]."')";
//$objQuery = mysql_query($strSQL);
$add = "insert into announcement(ann_title,ann_des,ann_pic,ann_date) values('$title','$des','$pic','$date')";
//$charset = "SET character_set_results=utf-8";
mysql_query($add) or die("Insert Error");
echo "<script>alert('เพิ่มข่าวประชาสัมพันธ์เรียบร้อยแล้ว');</script>";
}
mysql_close();
ob_end_flush();
?>
<a href="showAnn.php"><center><b>กลับไปยังหน้าข่าวประชาสัมพันธ์</b></center></a>
แล้วคือตอนนี้ถ้าไม่ upload ภาพ มันจะไม่ save อะไรสักอย่าง ลง db เลยอ่ะคะ
คือว่าอยากจะให้ user สามารถ upload รูปภาพเป็นภาพประกอบข่าวได้อ่ะค่ะ แต่ถ้า user ไม่เพิ่ม ก้อจะให้เป็นภาพ default อ่ะค่ะ จะโค้ดยังไงหรอคะ
ช่วยหน่อยนะคะ มึนตึ้บแร้วอ่าค่ะ ขอบคุณนะคะ ![](/images/bbcode/grin.gif?v=1001)
Tag : - - - -
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2009-04-04 06:36:30 |
By :
pochiiez |
View :
1274 |
Reply :
3 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองใช้หลักการนี้ดูครับ
ตอน user insert ข้อมูลลงไป ไม่ต้องไปสนใจเช็คอะไรครับ
เค้าจะใส่รูปหรือไม่ใส่รูป ก็ให้เค้า insert ไปครับ
แต่ตอนเวลาที่จะ out ออกมา ค่อยมาเช็คครับ เช่น
Code (PHP)
<?php
if(trim($pic == "")) $pic = 'default.jpg'; // ค่า $pic คือค่าจากฟิลด์ที่เก็บชื่อรูปที่ query ออกมาแล้วจาก database
?>
ให้มองแบบนี้ครับ
ฟิลด์ ann_pic จริงๆแล้วเก็บแค่ชื่อรูปใช่มั้ยครับ (มันก็คือ text ธรรมดานี่เองครับ)
ถ้าค่าใน ann_pic มันว่าง ก็แสดงว่าไม่มีรูป เราก็ให้ เจ้า ann_pic = ภาพ default ซะเลยครับ
แต่ถ้าค่า ann_pic มันไม่ว่าง มันก็จะไม่เข้าเงื่อนไขนี้ครับ
*วิธีนี้ยังมี backdoor ครับ เพราะเป็นแค่วิธีเบื้องต้นนะครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2009-04-04 09:07:05 |
By :
rasabut |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ถ้าป็นผมนะครับผมจะใช้วิธีแบบนี้ อาจจะบ้านๆไปนิดแต่คิดว่าน่าจะทำงานได้ตรงตามความต้องการครับ
Code (PHP)
<?php
ob_start();
include("connect.php"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<?
$title = $_POST["title"];
$des = $_POST["des"];
//$id = $_POST["id"];
$date = date("Y/m/d H:i:s", mktime(date("H"), date("i")+0, date("s")+0, date("m")+0 , date("d")+0, date("Y")+0));
$sql = "select * from announcement where ann_title ='$title'";
$result = mysql_query($sql) or die("Select error");
$count = mysql_num_rows($result);
if($count > 0)
{
echo "<script>alert('หัวข้อข่าวนี้มีแล้ว');history.back();</script>";
exit();
}
else
{
$pic = $_FILES["fileUpload"]["name"];
if(trim($pic == ""))
{
$pic = 'default.jpg';
}
else
{
copy($_FILES["fileUpload"]["tmp_name"],"myfile/".$pic);
}
//echo "Copy/Upload Complete<br>";
//*** Insert Record ***//
//$strSQL = "INSERT INTO files ";
//$strSQL .="(FilesName) VALUES ('".$_FILES["filUpload"]["name"]."')";
//$objQuery = mysql_query($strSQL);
$add = "insert into announcement(ann_title,ann_des,ann_pic,ann_date) values('$title','$des','$pic','$date')";
//$charset = "SET character_set_results=utf-8";
mysql_query($add) or die("Insert Error");
echo "<script>alert('เพิ่มข่าวประชาสัมพันธ์เรียบร้อยแล้ว');</script>";
}
mysql_close();
ob_end_flush();
?>
<a href="showAnn.php"><center><b>กลับไปยังหน้าข่าวประชาสัมพันธ์</b></center></a>
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2009-04-04 10:13:52 |
By :
zepherus |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ขอบคุณนะคะ![](/images/bbcode/smile.gif?v=1001)
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2009-04-04 11:07:02 |
By :
pochiiez |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 00
|