|
|
|
ช่วยแก้Code หน่อย พอเก็บSeve แล้วมันไม่เซพมันหายไป มีCodeด้วย ตัวอื่นลบได้แก้ได้หมดยกเว้น Enable/Disable |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?php
$objConnect = mysql_connect("localhost","root","12345678") ;
$objDB = mysql_select_db("config");
if($_GET["Action"] == "Save")
{
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
$strSQL = "UPDATE member SET ";
$strSQL .="ID = '".$_POST["ID$i"]."' ";
$strSQL .=",Username = '".$_POST["Username$i"]."' ";
$strSQL .=",Password = '".$_POST["Password$i"]."' ";
$strSQL .=",Name = '".$_POST["Name$i"]."' ";
$strSQL .=",Department = '".$_POST["Department$i"]."' ";
$strSQL .=",Phone = '".$_POST["Phone$i"]."' ";
$strSQL .=",Status = '".$_POST["Status$i"]."' ";
$strSQL .=",Allow = '".$_POST["Allow$i"]."' ";
$strSQL .="WHERE ID = '".$_POST["hdnID$i"]."' ";
$objQuery = mysql_query($strSQL);
}
}
$strSQL = "SELECT * FROM member ORDER BY ID ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="phpMySQLEditRecord2.php?Action=Save">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ID </div></th>
<th width="98"> <div align="center">Username </div></th>
<th width="198"> <div align="center">Password </div></th>
<th width="97"> <div align="center">Name </div></th>
<th width="59"> <div align="center">Department </div></th>
<th width="71"> <div align="center">Phone </div></th>
<th width="71"> <div align="center">Status </div></th>
<th width="71"> <div align="center">Allow </div></th>
</tr>
<?php
$i =0;
while($objResult = mysql_fetch_array($objQuery))
{
$i = $i + 1;
?>
<tr>
<td><div align="center">
<input type="hidden" name="hdnID<?php echo $i;?>" size="5" value="<?php echo $objResult["ID"];?>">
<input name="ID<?php echo $i;?>" type="text" id="ID<?php echo $i;?>" value="<?php echo $objResult["ID"];?>" size="5">
</div></td>
<td><input name="Username<?php echo $i;?>" type="text" id="Username<?php echo $i;?>" value="<?php echo $objResult["Username"];?>" size="20"></td>
<td><input name="Password<?php echo $i;?>" type="text" id="Password<?php echo $i;?>" value="<?php echo $objResult["Password"];?>" size="20"></td>
<td><input name="Name<?php echo $i;?>" type="text" id="Name<?php echo $i;?>" value="<?php echo $objResult["Name"];?>" size="20"></td>
<td><input name="Department<?php echo $i;?>" type="text" id="Department<?php echo $i;?>" value="<?php echo $objResult["Department"];?>" size="20"></td>
<td><input type="text" name="Phone<?php echo $i;?>" size="20" value="<?php echo $objResult["Phone"];?>"></td>
<td><input type="text" name="Status<?php echo $i;?>" size="20" value="<?php echo $objResult["Status"];?>"></td>
<td><div align="center">
<select name="Allow" id="Allow">
<option>Enable</option>
<option>Disable</option>
<?php
$strSQL2 = "SELECT * FROM member ORDER BY Allow ASC";
$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
while($objResult2 = mysql_fetch_array($objQuery2))
{
if($objResult["Allow"] == $objResult2["Allow"])
{
$sel = "selected";
}
else
{
$sel = "";
}
?>
<option value="<?php echo $objResult2["Allow"];?>" <?php echo $sel;?><?php echo $objResult2["Allow"];?>
<?php
}
?>
</select>
</div></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="Save">
<input type="hidden" name="hdnLine" value="<?php echo $i;?>">
</form>
<?php
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2017-07-03 15:54:25 |
By :
thanwa2 |
View :
687 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอนที่โพสต์ค่าไปนี่ ไม่มีบอกว่าอยู่ index แถวไหน แต่ตอนสั่งให้ update มีนี่ครับ
$strSQL .=",Allow = '".$_POST["Allow$i"]."' ";
น่าจะเป็นอย่างนี้หรือเปล่า
<select name="Allow<?php echo $i;?>" id="Allow<?php echo $i;?>">
Code (PHP)
<select name="Allow<?php echo $i;?>" id="Allow<?php echo $i;?>">
<option>Enable</option>
<option>Disable</option>
<?php
$strSQL2 = "SELECT * FROM member ORDER BY Allow ASC";
$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
while($objResult2 = mysql_fetch_array($objQuery2))
{
if($objResult["Allow"] == $objResult2["Allow"])
{
$sel = "selected";
}
else
{
$sel = "";
}
?>
<option value="<?php echo $objResult2["Allow"];?>" <?php echo $sel;?><?php echo $objResult2["Allow"];?>
<?php
}
?>
</select>
|
ประวัติการแก้ไข 2017-07-03 19:28:29
|
|
|
|
Date :
2017-07-03 19:26:57 |
By :
ccjpn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$strSQL2 = "SELECT * FROM member ORDER BY Allow ASC";
ควรมี where clause หรือไม่
อย่างที่ทำมัน มาทุก record
ข้อมูล record สุดท้าย จะทับ record แรก
|
|
|
|
|
Date :
2017-07-04 09:13:29 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|