|
 |
|
ใครพอทราบเรื่องอัพเดทข้อมูลใน ฐานข้อมูลช่วยเช็คโค้ทไห้ทีครับ ผมกดอัพเดทแล้วมันไม่อัพเดทอ่ะคับ |
|
 |
|
|
 |
 |
|
ผมทำตามวิธีของลิ้งนี้อ่ะคับ
https://www.thaicreate.com/php/php-mysql-update-edit-record.html
2ไฟล์แรกใชงานได้ แต่พอหน้าสุดท้ายคลิ๊ก submit แล้วมันไม่อัพเดทอ่ะคับ
a.php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("uogproject");
$strSQL = "SELECT * FROM pcshipping";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Shpping ID </div></th>
<th width="98"> <div align="center">UName </div></th>
<th width="198"> <div align="center">FName </div></th>
<th width="97"> <div align="center">LName </div></th>
<th width="59"> <div align="center">Address </div></th>
<th width="71"> <div align="center">ContactNo </div></th>
<th width="30"> <div align="center">Status </div></th>
<th width="87"> <div align="center">Update </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["ShippingID"];?></div></td>
<td><?=$objResult["UName"];?></td>
<td><?=$objResult["FName"];?></td>
<td><div align="center"><?=$objResult["LName"];?></div></td>
<td align="right"><?=$objResult["Address"];?></td>
<td align="right"><?=$objResult["ContactNo"];?></td>
<td align="right"><?=$objResult["Status"];?></td>
<td align="center"><a href="a1.php?spID=<?=$objResult["ShippingID"];?>">Edit</a></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
a1.php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<form action="a2.php?CusID=<?=$_GET["spID"];?>" name="frmEdit" method="post">
<?
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("uogproject");
$strSQL = "SELECT * FROM pcshipping WHERE ShippingID = '".$_GET["spID"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found CustomerID=".$_GET["spID"];
}
else
{
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Shpping ID </div></th>
<th width="98"> <div align="center">UName </div></th>
<th width="198"> <div align="center">FName </div></th>
<th width="97"> <div align="center">LName </div></th>
<th width="59"> <div align="center">Address </div></th>
<th width="71"> <div align="center">ContactNo </div></th>
<th width="30"> <div align="center">Status </div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="ShippingID" size="5" value="<?=$objResult["ShippingID"];?>"></div></td>
<td><input type="text" name="UName" size="20" value="<?=$objResult["UName"];?>"></td>
<td><input type="text" name="FName" size="20" value="<?=$objResult["FName"];?>"></td>
<td><div align="center"><input type="text" name="LName" size="2" value="<?=$objResult["LName"];?>"></div></td>
<td align="right"><input type="text" name="Address" size="5" value="<?=$objResult["Address"];?>"></td>
<td align="right"><input type="text" name="ContactNo" size="5" value="<?=$objResult["ContactNo"];?>"></td>
<td align="right"><input type="text" name="Status" size="5" value="<?=$objResult["Status"];?>"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<?
}
mysql_close($objConnect);
?>
</form>
</body>
</html>
a2.php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("uogproject");
$strSQL = "UPDATE pcshipping SET ";
$strSQL .="ShippingID = '".$_POST["ShippingID"]."' ";
$strSQL .=",UName = '".$_POST["UName"]."' ";
$strSQL .=",FName = '".$_POST["FName"]."' ";
$strSQL .=",LName = '".$_POST["LName"]."' ";
$strSQL .=",Address = '".$_POST["Address"]."' ";
$strSQL .=",ContactNo = '".$_POST["ContactNo"]."' ";
$strSQL .=",Status = '".$_POST["Status"]."' ";
$strSQL .="WHERE ShippingID = '".$_GET["spID"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS

|
|
 |
 |
 |
 |
Date :
2013-08-15 17:42:34 |
By :
nrs |
View :
653 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใส่ or die ด้วยครับจะได้รู้ว่า ตรงไหน
Code (PHP)
$objQuery = mysql_query($strSQL) or die ("Error [".$strSQL."]");
|
 |
 |
 |
 |
Date :
2013-08-15 23:32:44 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่ม tag <input type='hidden' name='spID' value='<?=$objResult["ShippingID"]?>'>
เปลี่ยนค่า where จาก $_GET[spID] เป็น $_POST[spID]
แล้วเอา ?CusID=<?=$_GET["spID"];?> ออกจาก action="a2.php?CusID=<?=$_GET["spID"];?>" เป็น action="a2.php"
|
 |
 |
 |
 |
Date :
2013-08-17 23:09:33 |
By :
jackkichan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|