|
 |
|
upload image with php การอัปโหลดรูปภาพเก็บในฐานข้อมูล |
|
 |
|
|
 |
 |
|
ขอบคุณ คุณ nutvaree ครับ ที่นำความรู้ดีๆมาบอกกัน 
|
 |
 |
 |
 |
Date :
2010-12-14 12:28:43 |
By :
mike_gt3 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะสำหรับความรู้จะลองเอาไปประยุกต์ค่ะ
|
 |
 |
 |
 |
Date :
2012-06-06 14:18:32 |
By :
rotchana |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมรบกวนสอบถามหน่อยน่ะคัรบ เพิ่งหัดเขียนครับ จากโค๊ดด้านบน ที่เป็น class วางตรงจุดไหนก้ได้เหรอครับผมกลัวผิดตำแหน่งอ่ะครับ
ถ้าจาก code ผมแล้ว ควรวางตรงไหนได้ครับ ถ้าโค๊ดจากข้างบนน่ะครับ เฉพาะตรง class อ่ะครับ
อันนี้จากโค๊ดผมครับ
Code (PHP)
<?php
include("top.php")
?>
<?php
$student_no = $_SESSION['user_no'] ;
$user_type = $_SESSION['user_type'] ;
?>
<!--#include file = "top.php" -->
<script language="VBScript" type="text/VBScript">
Function FrmOK()
Dim TheForm
Set TheForm = Document.Form1
TheForm.submit
End Function
Function FrmCancel()
Dim TheForm
Set TheForm = Document.Form2
TheForm.submit
End Function
</script>
<tr>
<td colspan="24"><table width="100%" height="351" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" background="images/template_edit_2_23.gif" bgcolor="#FFFFCC">
<?php
if ( $user_type == 5 ){
?>
<table width="995" border="0" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td width="132"> </td>
<td width="739" valign="top"><div align="right" class="text1"></div></td>
<td width="124" valign="top"> </td>
</tr>
<tr>
<td> </td>
<td valign="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#9900CC" class="text9">
<td width="100%" colspan="4" bgcolor="#3333FF" class="text9"><div align="center" class="text1">
<p class="text10">เพิ่มข่าวประชาสัมพันธ์ในโรงเรียน</p>
</div></td>
</tr>
<tr class="text9">
<td class="text13"> </td>
</tr>
<tr align="center" class="text9">
<td class="text13"> <div align="center">
<form name="form1" method="post" action="show_list_activity_news.php">
<table width="100%" border="0">
<tr class="text22">
<td width="9%"><div align="center">
<p class="text23">
<input type="hidden" name="add_status" value="1">
</p>
</div></td>
<td width="28%"><div align="center">
<p align="right" class="text23">วันเดือนปี</p>
</div></td>
<td width="2%"><div align="left">
<p> <span class="text23"> </span></p>
</div></td>
<td width="61%">
<?php
$today = getdate();
$mon = $today['mon'];
$year = $today['year'];
$day = $today['mday'];
?>
<select name="select_day">
<?php for ($i = 1; $i <= 31; $i++) { ?>
<option value="<?php echo $i ;?>" <?php if($i==$day ){ echo " selected " ;}?> ><?php echo $i?></option>
<?php } ?>
</select>
<?php $month_name = array("","มกราคม","กุมภาพันธ์","มีนาคม" ,"เมษายน" ,"พฤษภาคม" ,"มิถุนายน","กรกฎาคม" ,"สิงหาคม" ,"กันยายน" ,"ตุลาคม" ,"พฤศจิกายน","ธันวาคม" ) ?>
<select name="select_month">
<?php for ($i = 1; $i <= 12; $i++) { ?>
<option value="<?php echo $i ;?>" <?php if($i==$mon ){ echo " selected " ;}?> ><?php echo $month_name[$i]?></option>
<?php } ?>
</select> <select name="select_year">
<?php for ($i = $year-5; $i <= $year+5; $i++) { ?>
<option value="<?php echo $i ;?>" <?php if($i==$year ){ echo " selected " ;}?> ><?php echo chang_year($i )?></option>
<?php } ?>
</select> </td>
</tr>
<tr>
<td> </td>
<td><div align="right">
<p class="text23">หัวข้อข่าว</p>
</div></td>
<td> </td>
<td> <div align="left">
<input name="activity_news_head" type="text" size="50" value="">
</div></td>
</tr>
<tr>
<td> </td>
<td class="text23"><div align="right">รายละเอียดข่าว</div></td>
<td> </td>
<td> <textarea name="activity_news_detial" cols="49" rows="10" ></textarea>
</td>
</tr>
<tr>
<td> </td>
<td class="text23"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4"> <div align="center">
<input type="button" name="Button" value="บันทึก" onClick= FrmOK()>
<input type="button" name="Submit2" value="ยกเลิก" onClick= FrmCancel()>
</div></td>
</tr>
<tr>
<td colspan="4">
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
</table>
</form>
</div></td>
</tr>
<tr class="text9">
<td class="text12">
<form name="form2" method="post" action="show_list_activity_news.php">
<input type="hidden" name="add_status" value="0">
</form>
</td>
</tr>
<tr class="text9">
<td class="text12"><div align="center" class="text13"></div>
<div align="center"></div></td>
</tr>
</table>
<div align="left"></div></td>
<td valign="top"> </td>
</tr>
</table>
<?php
}
?>
<div align="right"></div>
<div align="center"></div></td>
</tr>
</table> </td>
</tr>
<?php
include("bottom.php")
?>
<!--#include file = "bottom.php" -->
|
 |
 |
 |
 |
Date :
2013-12-17 13:36:45 |
By :
itsup |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
วางไว้ข้างบนก็ได้ครับ ตรง include('top.php'); อ่ะ
อ่านการใช้งานตามคู่มือเลยครับ --> คลิก
|
ประวัติการแก้ไข 2013-12-17 13:49:40
 |
 |
 |
 |
Date :
2013-12-17 13:48:28 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับขอบคุณครับ
|
 |
 |
 |
 |
Date :
2013-12-17 14:10:37 |
By :
itsup |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากข้างบนผมทำตามหมดแล้วครับ แต่ปัญหาคือเมือเราอัพโหลดรูปแล้วน่ะครับ ตำแหน่งของรูปจะไปอยู่หน้าที่เราต้องการได้หรือเปล่าครับ
จากที่ผมทำประกาศข่าวได้แต่ต้องเพิ่มรูปด้วยน่ะครับ จากหน้าไฟล์ของผมครับ

ผมไม่เข้าใจครับว่าถ้าอัพโหลดแล้วห้มาอยู่ในห้นานี้จะทำอย่างไหรครับ

จากโค๊ดหน้าที่ 2 ครับ
Code (PHP)
<td>
<?php
include("top.php")
?>
<?php
$student_no = $_SESSION['user_no'] ;
$user_type = $_SESSION['user_type'] ;
// delete data
// ลบข้อมูลกิจกรรม
$del_status = $_POST['del_status'];
if ($del_status==1){
$query = "DELETE FROM activity_news WHERE activity_news_id= " . $_POST['activity_news_id'] . "";
//$query = "DELETE FROM activity_news WHERE activity_news_id= 5";
$result_id = db_query ($query, $link_id = 0);
//echo $_POST['activity_news_id'] ;
}
// edit data
// แก้ไขข้อมุลกิจกรรม
$edit_status = $_POST['edit_status'];
if ($edit_status==1){
if (trim($_POST['activity_news_head'] ) !=""){
$query = "UPDATE activity_news SET activity_news_day= ". $_POST['select_day'] . ", activity_news_month= ". $_POST['select_month'] . ", activity_news_year= ". $_POST['select_year'] . ",activity_news_head= '". $_POST['activity_news_head'] . "' ,activity_news_detial='" . $_POST['activity_news_detial'] . "' WHERE activity_news_id =" . $_POST['activity_news_id'] . "";
$result_id = db_query ($query, $link_id = 0);
// echo$_POST['activity_news_head'] ;
}
}
// add data
// เพิ่มข้อมุลกิจกรรม
$add_status = $_POST['add_status'];
if ($add_status==1){
if (trim($_POST['activity_news_head'] ) !=""){
$query= "select * from activity_news where activity_news_day = ". $_POST['select_day']." and activity_news_month =" . $_POST['select_month'] . " and activity_news_year = " . $_POST['select_year'] . " and activity_news_head= '" . $_POST['activity_news_head'] . "' and activity_news_detial = '" . $_POST['activity_news_detial'] . "'";
$result_id = db_query ($query, $link_id = 0);
$rows = db_num_rows ($result_id);
if ($rows <= 0)
{
$query= "INSERT INTO activity_news(activity_news_day, activity_news_month, activity_news_year, activity_news_head, activity_news_detial) VALUES(" .$_POST['select_day'] . "," . $_POST['select_month'] . "," . $_POST['select_year'] . ", '" . $_POST['activity_news_head'] . "', '" . $_POST['activity_news_detial'] . "')";
$result_id = db_query ($query, $link_id = 0);
//echo $_POST['activity_news_head'];
}
}
}
// เลือกข้อมูลที่ต้องการแสดง
$query = "select * from activity_news order by activity_news_id desc";
$result_id = db_query ($query, $link_id = 0);
?>
<!--#include file = "top.php" -->
<script language="VBScript" type="text/VBScript">
Function FrmOK()
Dim TheForm
Set TheForm = Document.Form1
TheForm.submit
End Function
Function FrmCancel()
Dim TheForm
Set TheForm = Document.Form2
TheForm.submit
End Function
</script>
<tr>
<td colspan="24"><table width="100%" height="351" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" background="images/template_edit_2_23.gif" bgcolor="#FFFFCC">
<?php
if ( $user_type == 5 or $user_type == 7 or $user_type == 8 ){
?>
<table width="995" border="0" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td width="132"> </td>
<td width="739" valign="top"><div align="right" class="text1"><a href="menu_user.php">กลับสู่เมนูหลัก</a></div></td>
<td width="124" valign="top"> </td>
</tr>
<tr>
<td> </td>
<td valign="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#9900CC" class="text9">
<td width="100%" colspan="4" bgcolor="#3333FF" class="text9"><div align="center" class="text1">
<p class="text10">รายการข่าวประกาศ</p>
</div></td>
</tr>
<tr class="text9">
<td class="text13"> </td>
</tr>
<tr align="center" class="text9">
<td class="text13"> <div align="center">
<table width="100%" border="0">
<tr class="text22">
<td width="7%"><div align="center">
<p class="text23">ลำดับที่</p>
</div></td>
<td width="10%"><div align="center">
<p class="text23">วันเดือนปี</p>
</div></td>
<td width="40%"><div align="left">
<p> <span class="text23"> กิจกรรม</span></p>
</div></td>
<td width="10%"> </td>
<td width="10%"> </td>
<td width="10%"> </td>
</tr>
<?php
$i=1;
while($row = db_fetch_row ($result_id))
{
// แสดงข้อมูลข่าวกิจกรรม
?>
<tr>
<td><div align="center"><?php echo $i;?> </div></td>
<td> <div align="center"> <?php echo $row[3] ."-".$row[4]."-". chang_year($row[5] ) ;?></div></td>
<td> <?php echo $row[1];?></td>
<td> </td>
<td><div align="center"><a href="edit_activity_news.php?activity_news_id=<?php echo $row[0]?>">แก้ไข</a></div></td>
<td><div align="center"><a href="del_activity_news.php?activity_news_id=<?php echo $row[0]?>">ลบ</a></div></td>
</tr>
<?php
$i++;
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td colspan="3"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td colspan="3"><div align="right"><a href="add_activity_news.php">เพิ่มข่าว</a></div></td>
</tr>
</table>
</div></td>
</tr>
<tr class="text9">
<td class="text12"> </td>
</tr>
<tr class="text9">
<td class="text12">
</td>
</tr>
<tr class="text9">
<td class="text12"> </td>
</tr>
<tr class="text9">
<td class="text12"> </td>
</tr>
<tr class="text9">
<td class="text12"><div align="center" class="text13"></div>
<div align="center"></div></td>
</tr>
</table>
<div align="left"></div></td>
<td valign="top"> </td>
</tr>
</table>
<?php
}
?>
<div align="right"></div>
<div align="center"></div></td>
</tr>
</table> </td>
</tr>
<?php
include("bottom.php")
?>
<!--#include file = "bottom.php" -->
</td>
จะทำอย่างไหรดีครับ
|
 |
 |
 |
 |
Date :
2013-12-17 14:20:17 |
By :
itsup |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองทดสอบแล้วคับ ทำการ upload เข้า data base แล้วตามภาพน่ะครับ

แต่ปัญหาคือผมจะดึงเข้ามาหน้านี้ได้อย่างไหรครับ รบกวนช่วยดูทีครับ
จากหน้าข่าวที่ผมได้เคยโพสต์ไล้วน่ะครับตอนแสดงข่าวน่ะครับ
|
 |
 |
 |
 |
Date :
2013-12-17 15:48:03 |
By :
itsup |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในตาราง tbl_images เพิ่มอีกฟิลด์นึงเพื่อเก็บ id ของบทความหรือกระทู้ครับ เวลาดึงภาพมาโชว์ก็ WHERE forum_id ครับ (น่าจะนึกภาพออกนะครับ)
|
 |
 |
 |
 |
Date :
2013-12-17 15:58:21 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-12-17 16:03:17 |
By :
kitisak053 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมอัพโหลด CSV ไม่ฟ้องerror ครับ ...แต่ทำไมมันไม่เข้า database อ่ะ echo ก็แล้วนะครับ



|
 |
 |
 |
 |
Date :
2015-03-03 15:25:39 |
By :
ศิวกร |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันดับแรก เช็คดูครับว่าโครงสร้างคำสั่ง INSERT คุณเขียนถูกหรือเปล่า? โดยปกติแล้วมันไม่น่าจะมี WHERE... อะไรนะครับ
2. แนะนำให้ตั้งกระทู้ใหม่ครับ
3. อย่าแคปหน้าจอในส่วนของโค้ด เพราะคนที่มาตอบส่วนใหญ่ขี้เกียจพิมพ์(รวมถึงผมด้วย) เลยทำให้ขี้เกียจตอบ
4. เอาโค้ดมาวางเลย โดยใช้รูปแบบแสดงผลแบบ PHP Code ที่ admin เค้าจัดบริการไว้ให้เพื่อให้ดูง่าย และไล่โค้ดได้ง่าย
5. ลอง debug error ดูการทำงานแต่ละส่วนดูครับ
5.1. debug ในส่วนของการอ่านข้อมูลจากไฟล์ CSV และ Debug ในส่วนของการ Query ได้แก่
Code (PHP)
#...โค้ดด้านบนของคุณ ...
while($objArr = ......){
print_r($objArr); #ลองดูว่าข้อมูลสามารถอ่านได้หรือไม่
....โค้ดในส่วนของ INSERT....
$objQuery = mysql_query($strSQL) or die(mysql_error()); #ดูว่าสามารถ query ได้หรือไม่?
}
ก็ประมาณนี้  
|
 |
 |
 |
 |
Date :
2015-03-03 16:01:15 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|