GORAGOD.com

freelance, web developer, web designer, hosting, domain name

เกียวกับ WYSIWYG อ่ะครับอาจารให้ใช้ตัวนี้อ่ะครับคือผม ใช้ไม่เปงอ

เกียวกับ   WYSIWYG  อ่ะครับอาจารให้ใช้ตัวนี้อ่ะครับคือผม ใช้ไม่เปงอ่ะ ผมจะบรรทึกลงฐานข้อมูลอ่ะ ผมต้องแก่ตรงไหน


<script language="JavaScript" type="text/javascript" src="wysiwyg.js">
</script>
<form name="example" method="get">
<textarea id="textarea1" name="test1" style="height: 170px; width: 500px;">

</textarea>
<script language="javascript1.2">
generate_wysiwyg('textarea1');
</script>

</form>


















ส่วนนี้โค้ดผมอ่ะครับ 










<?php
session_start();

// เช็คว่า User ได้ผ่านการ Login มาหรือไม่ (ถ้าไม่ได้ Login มาให้ส่งต่อไปหน้าไหนก็ใส่ URL ลงไปครับ ตรงตำแหน่ง login.php)
if (!isset($_SESSION[login])) {
     header("Location:login_admin.php");
     exit;
}

?>
<?
ob_start(); session_start();
function random_password($len)
{
srand((double)microtime()*10000000);
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$ret_str = "";
$num = strlen($chars);
for($i = 0; $i < $len; $i++)
{
$ret_str.= $chars[rand()%$num];
$ret_str.="";
}
return $ret_str;
}
$act=$_GET['act'];
$id=$_GET['id'];
$actb=$_POST['actb'];
include("connect.php");

 if($act == "bdel") {
 mysql_query("delete from news_3 where id=$id");
 }
 if($actb == "fmNews") {
 
 if (!defined('UPLOADDIR')) define('UPLOADDIR', (dirname(__FILE__) ."/download") );

if (is_uploaded_file($_FILES['pic1']['tmp_name'])) {
$File_tmpname1 = $_FILES["pic1"]["tmp_name"];
$File_name1 = $_FILES["pic1"]["name"];
$File_type1 = $_FILES["pic1"]["type"];
$File_extension1 = substr($File_type1,(strrpos($File_type1,"/")+1));
$File_size1 = $_FILES["pic1"]["size"];


$pic1 = random_password(7);
$now1 = date("Dgis");
$pic1 = $now1.$pic1.".gif";

move_uploaded_file($File_tmpname1, (UPLOADDIR . "/" . $pic1));
}
if (is_uploaded_file($_FILES['pic2']['tmp_name'])) {
$File_tmpname2 = $_FILES["pic2"]["tmp_name"];
$File_name2 = $_FILES["pic2"]["name"];
$File_type2 = $_FILES["pic2"]["type"];
$File_extension2 = substr($File_type2,(strrpos($File_type2,"/")+1));
$File_size2 = $_FILES["pic2"]["size"];


$pic2 = random_password(7);
$now2 = date("Dgis");
$pic2 = $now2.$pic2.".gif";


move_uploaded_file($File_tmpname2, (UPLOADDIR . "/" . $pic2));
}

 $name=$_POST['aut'];
 $dd=$_POST['dd'];
 $mm=$_POST['mm'];
 $yy=$_POST['yy'];
 $tle=$_POST['tle'];
 $txt=$_POST['txt'];
 $now=date("H:i:s");
 mysql_query("INSERT INTO news_3 (ds,ms,ys,title,mes,times,aut,pic1,pic2) values('$dd','$mm','$yy','$tle','$txt','$now','$name','$pic1','$pic2')");

?>
<html>
<head>
<title>เพิ่มข่าว</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<style type="text/css">
<!--
body {  margin: 0px  0px; padding: 0px  0px}
a:link { color: #005CA2; text-decoration: none}
a:visited { color: #005CA2; text-decoration: none}
a:active { color: #0099FF; text-decoration: underline}
a:hover { color: #0099FF; text-decoration: underline}
-->

</style>

</head>

<body bgcolor="#FFFFFF">
<div align="center">
  <table width="768" border="0" cellspacing="0" cellpadding="0" height="106">
    <tr>
      <td background="image/admin/header.gif">&nbsp;</td>
    </tr>
  </table>
  <table width="768" border="0" cellspacing="0" cellpadding="0" height="56">
    <tr>
      <td background="image/admin/m_a.gif">&nbsp;</td>
    </tr>
  </table>
  <table width="768" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td background="image/admin/bg.gif" valign="top">
        <div align="center">
          <table width="742" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td valign="top">
                <div align="center">
                  <p align="center"><b><font face="MS Sans Serif" size="2" color="#0000FF">ระบบจัดการ
                    Admin Tools</font></b></p>
                  <p align="center"><b><font face="MS Sans Serif" size="2" color="#0000FF">เพิ่มข่าว<br>
                    </font></b></p>
                  <table width="650" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>
                        <form name="form2" method="post" action="add_news3.php "enctype="multipart/form-data" >
                          <table width="650" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="110"><font face="MS Sans Serif" size="1" color="#000000">วันที่
                                : </font></td>
                              <td width="58">
                                <table width="61" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td><font face="MS Sans Serif" size="1" color="#000000">
                                      <input type="text" name="dd" size="2" value="<? $dd=date(d);$mm=date(m);$yy=date(Y); echo"$dd";?>" maxlength="2">
                                      </font></td>
                                  </tr>
                                </table>
                              </td>
                              <td width="76">
                                <table width="50" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td><font face="MS Sans Serif" size="1" color="#000000">
                                      <input type="text" name="mm" size="2" value="<? echo"$mm"; ?>" maxlength="2">
                                      </font></td>
                                  </tr>
                                </table>
                              </td>
                              <td width="406">
                                <table width="194" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td><font face="MS Sans Serif" size="1" color="#000000">
                                      <input type="text" name="yy" size="4" value="<? echo"$yy"; ?>" maxlength="4">
                                      </font></td>
                                  </tr>
                                </table>
                              </td>
                            </tr>
                          </table>
                          <br>
                          <table width="438" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="111"><font face="MS Sans Serif" size="1" color="#000000">หัวข้อข่าว
                                : </font></td>
                              <td width="327"><font face="MS Sans Serif" size="1" color="#000000">
                                <input type="text" name="tle" size="50">
                                </font></td>
                            </tr>
                          </table>
                          <br>
                          <table width="438" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="111"><font face="MS Sans Serif" size="1" color="#000000">รายละเอียด
                                : </font></td>
                              <td width="327"><font face="MS Sans Serif" size="1" color="#000000">
                                <textarea name="txt" cols="50" rows="3"></textarea>
                                <input type="hidden" name="actb" value="fmNews">
                                </font></td>
                            </tr>
                          </table>
                          <br>
                          <table width="366" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="110" height="35"><font face="MS Sans Serif" size="1" color="#000000">เพิ่มข่าวโดย
                                : </font></td>
                              <td width="256" height="35"><font face="MS Sans Serif" size="1" color="#000000">
                                <input type="text" name="aut" size="20" value="<? echo "admin"; ?>">
                                </font></td>
                            </tr>
                          </table>
                          <br>
                          <table width="366" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="110" height="35"><font face="MS Sans Serif" size="1" color="#000000">ภาพข่าว
                                : </font></td>
                              <td width="256" height="35"><font face="MS Sans Serif" size="1" color="#000000">
                                <input type="file" name="pic1">
                                </font></td>
                            </tr>
                          </table>
                          <br>
                          <table width="366" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="110" height="35"><font face="MS Sans Serif" size="1" color="#000000">icon
                                : </font></td>
                              <td width="256" height="35"><font face="MS Sans Serif" size="1" color="#000000">
                                <input type="file" name="pic2">
                                </font></td>
                            </tr>
                          </table>
                          <p><font face="MS Sans Serif" size="1" color="#000000">
                            <input type="submit" name="Submit32222" value="เพิ่มข่าว">
                            </font><br>
                          </p>
                        </form>
                        <div align="center">
                          <table width="649" border="0" cellspacing="0" cellpadding="0">
                            <tr bgcolor="#0000FF" bordercolor="#000000">
                              <td width="25" height="26"><b><font face="MS Sans Serif" size="1" color="#000000">
                                </font><font face="MS Sans Serif" size="1" color="#000000">
                                <?
$host="localhost";
$username="root";
$pass_word="2124";
$db="tc";
$tb="news_3";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
mysql_db_query($db,"SET NAMES tis620");
$sql="Select * From $tb ORDER BY id DESC";
/* ตั้งค่า แสดงผลต่อหน้า $Per_Page */

$Per_Page =5;
if(!$Page)
$Page=1;

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$result = mysql_query($sql);
$Page_start = ($Per_Page*$Page)-$Per_Page;
$Num_Rows = mysql_num_rows($result);

if($Num_Rows<=$Per_Page)
$Num_Pages =1;
else if(($Num_Rows % $Per_Page)==0)
$Num_Pages =($Num_Rows/$Per_Page) ;
else
$Num_Pages =($Num_Rows/$Per_Page) +1;

$Num_Pages = (int)$Num_Pages;

if(($Page>$Num_Pages) || ($Page<0))
print "<center><b>จำนวน $Page มากกว่า $Num_Pages ยังไม่มีข้อความ<b></center>";
$sql = "Select * From $tb ORDER BY id DESC LIMIT $Page_start , $Per_Page";
//ส่วนแสดงผล
$result = mysql_query($sql);
While($row= mysql_fetch_array($result)){
$id=$row["id"];
$title=$row["title"];
$txt=$row[mes];
$aut=$row[aut];
$ds=$row[ds];
$ms=$row[ms];
$ys=$row[ys];
?>
                                </font><font face="MS Sans Serif" size="1" color="#0000FF"></font></b></td>
                              <td width="343" height="26">
                                <div align="center"><font face="MS Sans Serif"><font size="1"><font color="#0000FF"><b><font color="#FFFFFF">หัวข้อข่าว</font></b></font></font></font></div>
                              </td>
                              <td width="80" height="26">
                                <div align="center"><b><font face="MS Sans Serif" size="1" color="#FFFFFF">ผู้ลงข่าว</font></b></div>
                              </td>
                              <td width="83" height="26">
                                <div align="center"><b><font face="MS Sans Serif" size="1" color="#FFFFFF">วันที่ลงข่าว</font></b></div>
                              </td>
                              <td width="63" height="26">
                                <div align="center"><b><font face="MS Sans Serif" size="1" color="#FFFFFF">แก้ไขข่าว</font></b></div>
                              </td>
                              <td width="55" height="26">
                                <div align="center"><b><font face="MS Sans Serif" size="1" color="#FFFFFF">ลบข่าว</font></b></div>
                              </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                              <td width="25" height="7">&nbsp;</td>
                              <td width="343" height="7"><font face="MS Sans Serif" size="1" color="#000000">
                                <?= $title;
?>
                                </font></td>
                              <td width="80" height="7">
                                <div align="center"><font face="MS Sans Serif" size="1" color="#000000">
                                  <? echo "$aut"; ?>
                                  </font></div>
                              </td>
                              <td width="83" height="7"><font face="MS Sans Serif" size="1" color="#000000">
                                <? echo "$ds"; ?>
                                -
                                <? echo "$ms"; ?>
                                -
                                <? echo "$ys"; ?>
                                </font></td>
                              <td width="63" height="7">
                                <div align="center"><font face="MS Sans Serif" size="1" color="#000000"><font face="MS Sans Serif" size="1" color="#0000FF"><a href="edit_news3.php?id=<?echo"$id"; ?>">แก้ไข</a></font></font></div>
                              </td>
                              <td width="55" height="7">
                                <div align="center"><font face="MS Sans Serif" size="1" color="#000000"><a href="add_news3.php?act=bdel&id=<?echo "$id"; ?>">ลบ</a>
                                  </font></div>
                              </td>
                            </tr>
                            <tr>
                              <td width="25"><font face="MS Sans Serif" size="1" color="#000000">
                                <?
}
mysql_close();
?>
                                </font></td>
                              <td width="343">&nbsp;</td>
                              <td width="80">&nbsp;</td>
                              <td width="83">&nbsp;</td>
                              <td width="63">&nbsp;</td>
                              <td width="55">&nbsp;</td>
                            </tr>
                          </table>
                        </div>
                      </td>
                    </tr>
                  </table>
                  <font size="1" face="MS Sans Serif" color="#000000">มีจำนวนข่าวทั้งหมด
                  <?= $Num_Rows;?>
                  ข่าว รวมทั้งหมด : <b>
                  <?=$Num_Pages;?>
                  </b> หน้า :
                  <?/* สร้างปุ่มย้อนกลับ */
if($Prev_Page)
echo " <a href='$PHP_SELF?Page=$Prev_Page'><< ย้อนกลับ </a>";
for($i=1; $i<$Num_Pages; $i++){
if($i != $Page)
echo "[<a href='$PHP_SELF?Page=$i'>$i</a>]";
else
echo "<b> $i </b>";
}
/*สร้างปุ่มเดินหน้า */
if($Page!=$Num_Pages)
echo "<a href ='$PHP_SELF?Page=$Next_Page'> หน้าถัดไป>> </a>";

?>
                  </font>
                  <p align="center"><b><font face="MS Sans Serif" size="1" color="#0000FF"><a href="admintools.php">เมนู</a></font></b><b><font face="MS Sans Serif" size="2" color="#0000FF">
                    </font></b></p>
                  <div align="center">
                    <map name="Map3">
                      <area shape="rect" coords="2,1,82,81" href="add_news3.php">
                    </map>
                    <map name="Map4">
                      <area shape="rect" coords="3,1,73,76" href="upload.php">
                    </map>
                  </div>
                </div>
              </td>
            </tr>
          </table>
          <br>
        </div>
      </td>
    </tr>
  </table>
  <table width="768" border="0" cellspacing="0" cellpadding="0" height="51">
    <tr>
      <td background="image/admin/foot.gif">&nbsp;</td>
    </tr>
  </table>
  <br>
  <font face="MS Sans Serif" size="1" color="#000000"> </font> <br>
  <font face="MS Sans Serif" size="1" color="#000000"> </font> </div>
</body>
</html>




 

08 เม.ย. 2552 4 2,597

การ บันทึกลง db ก็เหมือนการบันทึกด้วยฟอร์มปกติแหละถ้าอยากรู้ว่ามีอะไรส่งมาบ้าง ในตอนรับค่าก็ลองใช้ print_r($_POST); เพื่อดูค่าเอาละกัน แล้วก็จัดการไปตามปกติ
#1

รบกวนทำให้ดูหน่อยได้ป่าวครับ มือใหม่จิงอาจารให้ง่ายๆๆทั้งนั้นไม่ไหวจิงๆ
#2

<?php
  print_r($_POST);
?>

แค่นี้ถ้าอยากรู้ว่าฟอร์มส่งข้อมูลอะไรมาบ้าง หลังจากนั้นค่อยไปจัดการฟอร์มตามปกติ

แต่ถ้าไม่เข้าใจเรื่องฟอร์ม ผมแนะนำให้ศึกษาก่อน ระหว่างฟอร์มที่ใช้ WYSIWY กับไม่ใช้การ submit ไม่มีอะไรแตกตางกันครับ
#3

ขอบคุณครับ  แต่ก้อยังทำไม่เปงอยู๋ดี อ่ะ มันกดแล้วไม่เข้า ดาต้าเบด
#4
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 2M
^