|
 |
|
ช่วยดูที ครับ ลบได้ แก้ไข้ไม่ได้ ช่วยหาหน่อยว่าผิดตรงไหน |
|
 |
|
|
 |
 |
|
Code (PHP)
"UPDATE project SET Project_Name =$Project_Name where Project_ID =$ProID";
ไม่ต้องมี = หรือเปล่าคะ? เป็น update project set project_name ='$project_name' where project_id '$sProid';
แบบนี้เปล่า
|
 |
 |
 |
 |
Date :
2011-02-08 07:23:50 |
By :
mzchewiize |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะเป็นที่ Project_name นะครับ เพราะตัวนี้ของคุณน่าจะเป็น string ต้องใส่เครื่องหมาย ' ครอบตัวแปรไว้ครับ
เป็น
"UPDATE project SET Project_Name = '$Project_Name' where Project_ID = $ProID";
|
 |
 |
 |
 |
Date :
2011-02-08 08:14:03 |
By :
- - |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก่อนหน้านี้ ลอง
Code (PHP)
Echo $_GET[Action];
เพราะ้เงื่อนไขของ คุณ หากไม่ตรง Update หรือ Del มันก็ข้าม ไปเลย กรุณาเช็คด้วยครับ ว่า
ค่าที่รับมา เป็น ค่า 2 อย่างนี้หรือไม่
|
 |
 |
 |
 |
Date :
2011-02-08 09:49:40 |
By :
compeng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้เลยครับ
ค่าaction ก็มาละนะ
ลองtest sql ในฐานข้อมูล ก็ อัพเดทได้
Code (PHP)
<?
include "config.in.php";
$ProID=$_GET["ProID"] ;
$StuID=$_GET["StuID"] ;
$Project_Name=$_POST["Project_Name"] ;
if($_GET["Action"] == "Update")
{
$strSQL = "UPDATE project SET Project_Name ='$Project_Name' where Project_ID='$ProID'";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
header("location:$_SERVER[PHP_SELF]");
exit();
}
if($_GET["Action"] == "Del")
{
$strSQL1 = "DELETE FROM project WHERE Project_ID=$ProID AND Student_ID = $StuID ";
$query1 = mysql_query($strSQL1) or die('Error Delete ['.mysql_error().']');
$strSQL2="UPDATE student SET Project_ID=0 WHERE Student_ID=$StuID";
$objQuery = mysql_query($strSQL2);
if(!$objQuery)
{
echo "Error UPDATE [".mysql_error()."]";
}
header("location:$_SERVER[PHP_SELF]");
exit();
}
?>
<form id="form1" method="post" action="">
<table width="100%" border="0">
<tr>
<td align="center"> <span class="style1">ค้นจาก
<select name="by" class="style1" id="by">
<option value="Project_Name" selected="selected">ชื่อโครง</option>
<option value="Proect_Term ">ภาคเรียน</option>
</select>
</span> <span class="style1">คำที่ใช้ค้นหา</span>
<input type="text" name="keyword" id="keyword" />
<input name="button" type="submit" class="style1" id="button" value=" ค้นหาชื่อโครงงาน " /></td>
</tr>
</table>
</form>
<?
if($keyword==""){
$strSQL="SELECT project. * , student.Student_ID
FROM project, student
WHERE project.Project_ID = student.Project_ID
AND project.Project_ID >0";
}else{
$strSQL="SELECT project. * , student.Student_ID
FROM project, student
WHERE project.Project_ID = student.Project_ID
AND project.Project_ID >0 AND $by like '%$keyword%' ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 10; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
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;
}
$strSQL .=" order by Project_Year ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<form name="formadd" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnPro" value="">
<table width="600" border="1" align="center">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th colspan="5"> <div align="center">Name </div></th>
<th width="30"> <div align="center">Edit </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["Project_ID"] == $_GET["ProID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<?=$objResult["Project_ID"];?>
<input type="hidden" name="hdnProID" size="5" value="<?=$objResult["Project_ID"];?>">
</div></td>
<td colspan="5"><input type="text" name="Project_Name" size="20" value="<?=$objResult['Project_Name'];?>"></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="formadd.hdnProID.value='Update';formadd.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?
}
else
{
?>
<tr>
<td><div align="center"><?=$objResult["Project_ID"];?></div></td>
<td colspan="5"><?=$objResult["Project_Name"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&ProID=<?=$objResult["Project_ID"];?>&StuID<?=$objResult["Student_ID"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&ProID=<?=$objResult["Project_ID"];?>&StuID<?=$objResult["Student_ID"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
</tr>
</table>
<div align="center"><br>
<span class="style1">ทั้งหมด
<span class="style12">
<?= $Num_Rows;?>
</span>
จำนวนหน้า :
<span class="style14">
<?=$Num_Pages;?>
</span>
หน้า :
<strong>
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< กลับ</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>ถัดไป>></a> ";
}
?>
</div>
</form>
|
 |
 |
 |
 |
Date :
2011-02-08 11:56:41 |
By :
ckcr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สร้างหน้าใหม่ ชื่อ test_edit.php?ProID=(ใส่รหัสที่ต้องการแก้ไข)&Project_Name=TTTTTTT&Action=Update_id
Code (PHP)
include "config.in.php";
$ProID=$_GET["ProID"] ;
$Project_Name=$_GET["Project_Name"] ;
if($_GET["Action"] == "Update_id")
{
$strSQL = "UPDATE project SET Project_Name ='$Project_Name' where Project_ID='$ProID'";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
echo "ค่า Action =".$Action."<br>";
echo "ค่า ID =".$ProID."<br>";
echo "ค่า Project_Name =".$Project_Name."<br>";
/*header("location:$_SERVER[PHP_SELF]");
exit();*/
}
ข้างบน ไม่ทราบเหมือนกันว่า รับค่า Action จาก GET แล้ว รับค่า ชื่อ จาก POST ก็ยังงง อยู่นะครับ ที่คุณเขียน
|
ประวัติการแก้ไข 2011-02-09 09:35:30
 |
 |
 |
 |
Date :
2011-02-09 09:33:41 |
By :
compeng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|