Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > แก้ไขข้อมูลไม่ได้รบกวนดูโค้ดให้หน่อยได้ไหมค่ะ. ..ขอบคุณมา ณ. ที่นี้นะค่ะ ต้องส่งงานพรุ่งนี้ค่ะ



 

แก้ไขข้อมูลไม่ได้รบกวนดูโค้ดให้หน่อยได้ไหมค่ะ. ..ขอบคุณมา ณ. ที่นี้นะค่ะ ต้องส่งงานพรุ่งนี้ค่ะ

 



Topic : 088079

Guest




Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include ("connet.php");
?>
  <?

$page=$_GET[page];
if ($page==""){
$page=1;
}
$each=10;


$sql_news = "SELECT * FROM news;";
$result_news = mysql_query($sql_news);
$totals=mysql_num_rows($result_news);

$totalpages=ceil($totals/$each);
$goto=($page-1)*$each;

$sql_news="SELECT * FROM news ORDER BY news_id DESC limit $goto,$each;";
$result_news=mysql_query($sql_news);
?>



<?
//การสร้าง Autorun รหัสประเภทสินค้า นั่นเอง
$sql="select max(news_id) as news_id from news";
$result=mysql_query($sql) or die(mysql_error());//การ error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ส่วนใหญ่เป็นเพราะตรงนี้
$dbarr=mysql_fetch_array($result);
if($dbarr){
$total= $dbarr['news_id']+1;
if (strLen($total)=="1"){
$total="0".$total;
}else{
$total= $total;
}
}else{
$total= $id_news;
}

?>
<form method="post" action="news_action.php?do=add">
  <table width="587" border="0" align="center">
    <tr align="right" valign="bottom">
      <th scope="col">::<strong><img src="20121116050143551_easyicon_cn_32.png" alt="" width="20" height="20" /></strong> เพิ่มข่าวสารประชาสัมพันธ์::</th>
    </tr>
  </table>
  <table width="587" border="0" align="center">
    <tr align="right" >
      <td width="143">รหัสข่าวสาร ::</td>
<td width="434" align="left" ><?=$total; ?> 
    </td>
    </tr>
    <tr >
      <td align="right">หัวข้อข่าวสาร ::</td>
      <td><label for="news_title"></label>
      <input name="news_title" type="text" id="news_title" size="50" /></td>
    </tr>
    <tr >
      <td align="right">รายละเอียดข่าวสาร ::</td>
      <td><label for="news_detail"></label>
      <textarea name="news_detail" cols="50" rows="6" id="news_detail"></textarea></td>
    </tr>
    <tr >
      <td align="right">วันที่ประกาศ ::</td>
      <td><label for="news_date"></label>
        <input name="news_date" type="text" id="news_date" value="<?php echo date('Y-m-d');?>"   /></td>
    </tr>
    <tr align="right">
      <td colspan="2"><div align="center">
      <input type="submit" name="button" id="button" value="เพิ่มข่าวสาร" />
        <input type="reset" name="button2" id="button2" value="ยกเลิก" />
        <input type="hidden" name="id_news" value="<?=$total; ?>" />
        </div></td>
    </tr>
  </table>
  
</form>


  <table width="601" border="0" align="center">
    <tr>
      <th colspan="6" align="center" scope="col">จัดการข้อมูลข่าวประกาศ ประชาสัมพันธ์      </th>
    </tr>
    <tr align="center">
      <td width="80">ลำดับที่</td>
      <td width="126">หัวข้อข่าวสาร</td>
      <td width="154">วันที่ประกาศ</td>
      <td width="98">รายละเอียด</td>
      <td width="57">แก้ไข</td>
      <td width="60">ลบ</td>
    </tr>
    <?
  while ($dbarr_news = mysql_fetch_array($result_news)){
	  
?>
    <tr align="center">
     
      <td><? echo $dbarr_news['news_id'] ?></td>
      <td><? echo $dbarr_news['news_title'] ?></td>
      <td><? echo $dbarr_news['news_date'] ?></td>
     
      
       <td align="center"><a href="shownews1.php?ty=<?=$dbarr_news['news_id'] ?>"><img src="20121116050309842_easyicon_cn_128.png" width="20" height="20" /></a></td>
       
      <td><a href ="news_action.php?do=frmedit&id=<? echo $dbarr_news['news_id']; ?>"><img src="20121116050301729_easyicon_cn_80.png" alt="" width="20" height="20" /></a></td>
      
      <td align="center"><a href="news_action.php?do=delete&id=<? echo $dbarr_news['news_id'] ?>"><img src="20121116050436121_easyicon_cn_128.png" alt="" width="20" height="20" /></a></td>
    </tr>
     <?
  }
  ?> 
  
 
    <tr>
<td colspan="4">รวมทั้งหมด <?=$totals?> รายการ :
  <? //Code ใช้ เมื่อ จำนวนหน้ามากกว่า 1 หน้า
if($totalpages>1) {
for ($i=1;$i<=$totalpages;$i++){
if($i==$page) {
echo "<b>หน้า $page </b>";
} else {
echo " | <a href=\"news.php?page=$i\">$i</a>&nbsp;";
}
}
}

?></td>
</table>

Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "connet.php";
if ($_POST['do']=="add"){
	$id_news=$_POST['news_id'];
	$title=$_POST['news_title'];
	$detile=$_POST['news_detail'];
	$news_date=$_POST['news_date'];
	
	$sql="select * from news where news_title='$news_title'";
	$result=mysql_query($sql) or die(mysql_error());// error  Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource  แก้ตรงนี้
	$num=mysql_num_rows($result);
	
	if($num>0){
		echo"<h1>ชื่อหัวข้อข่าวสารซ้ำ</h1>";
		echo"<meta http-equiv='refresh' content='2;url=news.php'>";
	}else{
		$sql_add = "INSERT INTO news (news_id ,news_title,news_detail,news_date) VALUES ('$news_id','$news_title','$news_detail','$news_date');";
		$result_add=mysql_query($sql_add);
		echo "<script language='javascript'>";
	echo "alert('เพิ่มข้อมูลข่าวสารเรียบร้อยแล้ว');";
	echo "window.location='news.php';";
	echo "</script>";
		}
	}elseif ($_GET['do']=="delete"){
		$sql="DELETE FROM news WHERE news_id='$_REQUEST[id]';";
		$result=mysql_query($sql);
		
		if($result){
		echo "<script language='javascript'>";
		echo "alert('ลบข้อมูลข่าวสารเรียบร้อยแล้ว');";
		echo "window.location='news.php';";
		echo "</script>";
	}
	elseif ($_GET['do']=="frmedit"){//ต้องมีการโหลด From ขึ้นมาใหม่...ถ้า ['do']=="frmedit" จริง มันจะใช้คำสั่ง$sql="SELECT * FROM tbcategory WHERE catid =$_POST[id]"; คือเรียกขึ้นม่า 1 record 
			
			$sql="SELECT * FROM news WHERE news_id =$_GET[id]";//เมื่อคลิก ปุ่มแก้ไขมันจะส่งค่าไป
			$result=mysql_query($sql);
			$dbarr=mysql_fetch_array($result);
?>

<form method="post" action="news_action.php?do=edit">
  <table width="667" border="0" align="center">
    <tr align="right" valign="middle">
      <td scope="col">::แก้ไขข้อมูลข่าวสารประชาสัมพันธ์::</td>
    </tr>
  </table>
  <table width="667" border="0" align="center">
    <tr align="right" >
      <td width="151">รหัสข่าวสาร::</td>
<td align="left"><?=$dbarr['news_id']; ?></td>
    </tr>
     <tr >
      <td align="right">หัวข้อข่าวสาร ::</td>
      <td><label for="titlee"></label>
      <input name="news_title" type="text" id="news_title"  value="<?=$dbarr['news_title']; ?>"/></td>
    </tr>
   <tr >
      <td align="right">รายละเอียดข่าวสาร ::</td>
      <td><label for="news_detail"></label>
      <textarea name="news_detail" cols="50" rows="5" id="news_detail"><?=$dbarr['news_detail']; ?>
        </textarea></td>
    </tr>
    <tr >
      <td align="right">วันที่ประกาศ ::</td>
      <td><label for="news_date"></label>
        <input name="news_date" type="text" id="news_date"   value="<?=$dbarr['news_date']; ?>"   /></td>
    </tr>
    <tr align="right">
      <td colspan="2">
      <div align="center">
     <input type="hidden" name="id" value="<?=$dbarr['news_id'];?>">
      <input type="submit" name="button" id="button" value="บันทึก" />
        <input type="reset" name="button2" id="button2" value="ยกเลิก" />
        
        </div></td>
    </tr>
  </table>
</form>
<?
}elseif ($_GET['do']=="edit"){
	$news_id=$_POST['id'];
	$news_title=$_POST['news_title'];
	$news_detail=$_POST['news_detail'];
	$news_date=$_POST['news_date'];
	
	$sql_update = "UPDATE news SET news_title='".$news_title."',news_detail='".$news_detail."' WHERE news_id'".$_POST["id"]."'";
	$reslut_update=mysql_query($sql_update) or die(mysql_error());

	if($result_update){
		echo "<script language='javascript'>";
	echo "alert('แก้ไขข้อมูลข่าวสารเรียบร้อยแล้ว');";
	echo "window.location='news.php';";
	echo "</script>";
		echo "<meta http-equiv='refresh' content='2;url=news.php'>";
	}else{
		echo "<script language='javascript'>";
	echo "alert('ไม่สามารถแก้ไขข้อมูลข่าวสารได้');";
	echo "window.location='news.php';";
	echo "</script>";
	}
}
}
?>





Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, CakePHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-12-16 00:39:59 By : อัลต้า View : 814 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code
$sql_update = "UPDATE news SET news_title='".$news_title."',news_detail='".$news_detail."' WHERE news_id'".$_POST["id"]."'";
echo $sql_update;


เอา SQL ออกมาดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-16 08:10:54 By : mr.win
 


 

No. 2



โพสกระทู้ ( 3,843 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2012-12-16 08:10:54
รายละเอียดของการตอบ ::
เพิ่มเติมครับ

$sql_update = "UPDATE news SET news_title='".$news_title."',news_detail='".$news_detail."' WHERE news_id'".$_POST["id"]."'";

WHERE news_id'".$_POST["id"]."'"; ใส่ = ด้วยครับ WHERE news_id = '".$_POST["id"]."'";
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-16 09:56:00 By : mangkunzo
 

 

No. 3

Guest


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2012-12-16 08:10:54
รายละเอียดของการตอบ ::
แก้ไขตามที่พี่บอกแล้วก้อยังไม่ได้ค่ะ

ส่วนตรงนี้เป็น sql นะค่ะ
news


ตอบความคิดเห็นที่ : 2 เขียนโดย : mangkunzo เมื่อวันที่ 2012-12-16 09:56:00
รายละเอียดของการตอบ ::
ไม่ได้ค่ะแก้ตามที่บอกแล้วนะค่ะ. ..ขอบคุณมากค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-16 20:53:25 By : อัลต้า
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : แก้ไขข้อมูลไม่ได้รบกวนดูโค้ดให้หน่อยได้ไหมค่ะ. ..ขอบคุณมา ณ. ที่นี้นะค่ะ ต้องส่งงานพรุ่งนี้ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่