|
 |
|
จะทำลิงค์ ไปฟอร์มเพื่อแก้ไข กับ ลบ ทำยังไงครับ คือผมจะทำลิงค์จากหน้านี้นะครับ ไปหน้า edit และ delete |
|
 |
|
|
 |
 |
|
<td>แก้ไข</td><td>ลบ</td>
เพิ่มเท็กลิงค์ไปหาไฟล์แก้ไข หรือลบ พร้อมไอดี
<td><a href='edit.php?id=$id'>แก้ไข</a></td><td><a href='delete.php?id=$id'>ลบ</a></td>
แค่นี้แหละ ได้ผลลัพธ์ตามต้องการแย้วววว
|
 |
 |
 |
 |
Date :
2009-09-23 11:26:23 |
By :
NanoTHoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ้วววววววววสุดยอดมากมายครับคุณนาโน เก่งโครตๆๆๆๆๆ ได้แล้วครับ แบบว่าตอนแรกผมลิงค์ธรรมดามันไม่ได้งงมากๆๆขอบคุณจริงๆครับ เด๋วถามใหม่นะครับ
|
 |
 |
 |
 |
Date :
2009-09-23 11:30:57 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถามต่อนะครับ แล้วทำยังไงให้มัน แสดงค่าเดิมที่เราจะแก้ไขครับ พอดีมันมีหลายข้อมูลอ่าครับ
ถ้าไงเข้าไปดูที่
http://www.nuengmongkol.co.th/work
user:admin
pass:1234
|
 |
 |
 |
 |
Date :
2009-09-23 11:34:11 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไปตามลิงค์ที่ให้ไว้นะครับ แล้วจะเข้าใจ
|
 |
 |
 |
 |
Date :
2009-09-23 11:39:14 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอามาให้ดูดีกว่าเนอะ
PHP MySQL Delete Record
Code (PHP) phpSQLServerDeleteRecordList.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
<td align="center"><a href="phpMySQLDeleteRecord.php?CusID=<?=$objResult["CustomerID"];?>">Delete</a></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>

Code (PHP)phpMySQLDeleteRecord.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "DELETE FROM customer ";
$strSQL .="WHERE CustomerID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Record Deleted.";
}
else
{
echo "Error Delete [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>

|
 |
 |
 |
 |
Date :
2009-09-23 12:55:30 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
PHP MySQL Edit/Update Record
Code (PHP)phpMySQLEditRecordList.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
<th width="30"> <div align="center">Edit </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
<td align="center"><a href="phpMySQLEditRecordForm.php?CusID=<?=$objResult["CustomerID"];?>">Edit</a></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>

Code (PHP) phpMySQLEditRecordForm.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<form action="phpMySQLEditRecordSave.php?CusID=<?=$_GET["CusID"];?>" name="frmEdit" method="post">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer WHERE CustomerID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found CustomerID=".$_GET["CusID"];
}
else
{
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID" size="5" value="<?=$objResult["CustomerID"];?>"></div></td>
<td><input type="text" name="txtName" size="20" value="<?=$objResult["Name"];?>"></td>
<td><input type="text" name="txtEmail" size="20" value="<?=$objResult["Email"];?>"></td>
<td><div align="center"><input type="text" name="txtCountryCode" size="2" value="<?=$objResult["CountryCode"];?>"></div></td>
<td align="right"><input type="text" name="txtBudget" size="5" value="<?=$objResult["Budget"];?>"></td>
<td align="right"><input type="text" name="txtUsed" size="5" value="<?=$objResult["Used"];?>"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<?
}
mysql_close($objConnect);
?>
</form>
</body>
</html>

Code (PHP)phpMySQLEditRecordSave.php
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "UPDATE customer SET ";
$strSQL .="CustomerID = '".$_POST["txtCustomerID"]."' ";
$strSQL .=",Name = '".$_POST["txtName"]."' ";
$strSQL .=",Email = '".$_POST["txtEmail"]."' ";
$strSQL .=",CountryCode = '".$_POST["txtCountryCode"]."' ";
$strSQL .=",Budget = '".$_POST["txtBudget"]."' ";
$strSQL .=",Used = '".$_POST["txtUsed"]."' ";
$strSQL .="WHERE CustomerID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>


|
 |
 |
 |
 |
Date :
2009-09-23 13:00:40 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ กำลังทำความเข้าใจนะครับ แบบว่า ทำตามทั้งหมดแล้ว แต่ไม่รู้ผิดตรงไหน
เวลากดที่แก้ไข ข้อมูลในฟิลนั้นๆไม่ออก และเวลาลบ ฐานข้อมูลไม่ลบตามครับ แต่ไม่มีฟ้องผิดพลาดตรงไหนนะครับ ทำยังไงดี หรือว่าต้องเอาซอสโค๊ดมาให้ดูด้วยครับ
|
 |
 |
 |
 |
Date :
2009-09-24 09:11:38 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2009-09-24 23:35:35 |
By :
giroo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โทษทีคุณอ้น แบบว่าโพสไปแล้วไม่ได้ย้อนกลับมาดู เลยไม่รู้ง่าคุณพาดพิงถึงผมไว้ กระผมคิดว่าท่านประธานครับกรุณาให้เขาถอนคำพูดครับ อ้าวเอ้ย คนละเรื่องและ อิอิอิ
ตกลงทำได้หรือยังครับ ตามที่คุณ pokultra โพสไว้ก็มีให้ครบสูตรเลย หวังว่าคงได้แล้วนะครับ หรือว่าติดปัญหาตรงไหนอีกครับ
|
 |
 |
 |
 |
Date :
2009-09-25 00:21:59 |
By :
NanoTHoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นยังไงบ้างครับ ได้หรือยังเอ่ย
ถ้าติดปัญหาตรงไหนเอา error หรือ code ที่คุณอ้นคุง เขียนไว้มาแปะเลยครับ เพื่อนๆ จะได้เห็นและลงไม้ลงมือช่วยกันแก้ปัญหา ตามนโยบายไทยเข้มแข็ง   
|
 |
 |
 |
 |
Date :
2009-09-25 10:08:08 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เข้ามแข็งแต่นโยบายนะสิคุณ pokultra เมื่อไหร่ไทยจะแข็งแท้สักทีหนอชาติไทยจะได้เจริญสักที
ผมว่าน่าจะใช้คำนี้ดีกว่า ร่วมด้วยช่วยกัน มูลนิธิ อิอิอิ
|
 |
 |
 |
 |
Date :
2009-09-25 12:09:10 |
By :
NanoTHoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ติดครับ ติดตรงที่พอกดแก้ไข นะครับ ข้อมูลไม่ออก มีแต่ฟอร์มกับช่องว่างๆ และพอกดลบ ระบบบอกว่าลบเรียบร้อยแล้ว แต่ไปดูในฐานกลับเหมือนเดิมครับไม่มีการลบแต่อย่างใด
ปล.ขอบคุณทุกๆท่านมากๆนะครับ
|
 |
 |
 |
 |
Date :
2009-09-25 12:22:45 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา code มาชมหน่อยครับ
ถ้าเอามาเป็นหน้าๆ อย่างที่ผมเอามาให้ดูได้ก็จะดีมากคับ
งืมๆๆๆ
|
 |
 |
 |
 |
Date :
2009-09-25 12:50:57 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่เป็นหน้า form นะครับ
<html>
<head>
<title>ข้อมูลการ์ตูน</title>
<style type="text/css">
<!--
.style1 {
font-family: Tahoma;
font-size: 11px;
}
.style3 {font-family: Tahoma; font-size: 11px; color: #FF0000; }
.style4 {color: #000000}
.style5 {font-family: Tahoma; font-size: 11px; color: #000000; }
-->
</style>
</head>
<body>
<form action="form3_save.php?CarID=<?=$_GET["carid"];?>" name="form3_edit" method="post">
<?
include('inc.php');
$sql = "SELECT * FROM cartoon WHERE cartoon_id = '".$_GET["carid"]."' ";
$objQuery = mysql_query($sql);
$objResult = mysql_fetch_array($objQuery);
/* if(!$objResult)
{
echo "แก้ไขไม่สำเร็จ=".$_GET["carid"];
}
else
{ */
?>
<table width="413" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="85" scope="col"><div align="right"><span class="style3"><span class="style5">รหัสการ์ตูน</span><span class="style3">*</span> <strong>:</strong></span></div></td>
<td width="144" scope="col"><label>
<input name="cartoon_id" type="text" id="cartoon_id" value="<?=$objResult["cartoon_id"];?>" onblur="MM_validateForm('cartoon_id','','RisNum');return document.MM_returnValue" maxlength="4" />
</label></td>
<td width="184" scope="col"> </td>
</tr>
<tr>
<td><div align="right"><span class="style1">ชื่อการ์ตูน</span><span class="style3"><span class="style3">*</span><strong> :</strong></span></div></td>
<td colspan="2"><label>
<input name="cartoon_name" type="text" id="cartoon_name" value="<?=$objResult["cartoon_name"];?>" onblur="MM_validateForm('cartoon_id','','R','cartoon_name','','R');return document.MM_returnValue" size="50" maxlength="50" />
</label></td>
</tr>
<tr>
<td><div align="right"><span class="style1">จำนวนเล่ม</span><span class="style3"><span class="style3">*</span> <strong>:</strong></span></div></td>
<td><label>
<input name="num" type="text" id="num" value="<?=$objResult["num"];?>" onblur="MM_validateForm('num','','RinRange1:99');return document.MM_returnValue" maxlength="2" />
</label></td>
<td> </td>
</tr>
<tr>
<td><div align="right"><span class="style1">สำนักพิมพ์</span><span class="style3"><span class="style3">*</span> <strong>:</strong></span></div></td>
<td><label>
<input name="publisher" type="text" id="publisher" value="<?=$objResult["publisher"];?>" onblur="MM_validateForm('publisher','','R');return document.MM_returnValue" maxlength="30" />
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label></label>
<label></label>
<label></label></td>
<td><input type="button" name="insert" id="insert" value="เพิ่ม" />
<input type="submit" name="reccord" id="reccord" value="บันทึก" />
<input type="reset" name="reset" id="reset" value="ยกเลิก" /></td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-09-25 12:54:56 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่วนนี่หน้า code save
<html>
<head>
<title>ข้อมูลการ์ตูน</title>
</head>
<body>
<?
include('inc.php');
$sql = "UPDATE cartoon SET ";
$sql .="cartoon_id = '".$_POST["cartoon_id"]."' ";
$sql .=",cartoon_name= '".$_POST["cartoon_name"]."' ";
$sql .=",num= '".$_POST["num"]."' ";
$sql .=",publisher = '".$_POST["publisher"]."' ";
$sql .="WHERE cartoon_id = '".$_GET["carid"]."' ";
$objQuery = mysql_query($sql);
if($objQuery)
{
echo "บันทึกเรียบร้อยแล้ว.";
}
else
{
echo "ไม่สามารถบันทึกได้ ";
}
mysql_close($conn);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-09-25 12:55:30 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะเกี่ยวไหมครับที่ว่า ส่งค่าไปแบบ get แล้วรับเป็นแบบ Post
|
 |
 |
 |
 |
Date :
2009-09-25 12:57:18 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่งไปแบบเก็ต เวลารับก็ต้องเก็ต ส่งไปโพสเวลารับก็ต้องโพส แต่ถ้าไม่อยากแยกให้ใช้ $_REQUEST แทนครับ เพราะรับได้ทั้งเก็ตและโพส
ทีนี้มาดูจากที่คุณถามว่าส่งไปแบบโพส เวลารับเป็นเก็ต ตรงนี้ในหน้าฟอร์มผมไม่เห็นว่าคุณจะส่งเก็ตเลย เมธอดยังเป็นโพสครับ เรื่องของข้อมูลไม่ออกมาแสดงตรงนี้น่าจะอยู่ทีหน้าส่งไอดีมาให้หน้าฟอร์มของคุณมากกว่าครับ เพราะว่าคุณต้องการให้แสดงข้อมูลเก่าก่อนการแก้ไขในหน้าฟอร์ม คุณจะต้องรับไอดีมาจากหน้าวิวเพื่อมาเลือกรายการให้ตรงกับที่คุณต้องการแก้ไขนะครับ ดังนั้นคุณต้องทดสอบก่อนว่าค่าที่ส่งมาถูกต้องหรือไม่โดย echo $id ที่รับเข้ามาครับ ถ้าถูกต้องแล้ว ต้องตรวจสอบต่อไปว่าคำสั่งเอสคิวแอลโดยเฉพาะเงื่อนไขของคุณถูกต้องหรือเปล่า ถ้าถูกแล้วก็ต้องตรวจสอบต่อไปอีกคว่าค่าที่จะนำไปแสดงในแท็กบ็อกถููกต้องหรือเปล่า คุณทดลองไล่ดูตามนี้ก่อนครับ
|
 |
 |
 |
 |
Date :
2009-09-25 13:35:17 |
By :
NanoTHoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|