|
|
|
ผม edit ข้อมูลแล้วเก็บลงในฐานข้อมูลไม่ได้ครับ ช่วยผมด้วยครับ |
|
|
|
|
|
|
|
เชื่อมฐานข้อมูล
Code (PHP)
<?php
$host = "localhost";
$user = "root";
$pass = "root";
$dbname = "db_drinkup";
$objConnect= mysql_connect("$host","$user","$pass") or die ("Error Connect to Database"); //เชื่อมต่อฐานข้อมูล
$objDB = mysql_select_db("$dbname"); //เลือกฐานข้อมูล
$strSQL = "select * from userinfo" ; //เลือกตารางจากฐานข้อมูล
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); //เลือกรูปแบบการดึงข้อมูล
?>
</body>
</html>
edit_record.php
Code (PHP)
<?php
require_once('connect_db.php'); //เรียกหน้าเชื่อต่อฐานข้อมูล
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>list_record</title>
</head>
<body>
<table width="750" border="0" bgcolor="#CCCCCC">
<tr>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">CustomerID</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">logname</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">password</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">name</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">gender</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">age</div></th>
<th width="150"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">email</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">edit</div></th>
</tr>
<?php
while($objResult = mysql_fetch_array ($objQuery)) //ดึงข้อมูลในรูปแบบอาเรย์
{
?>
<tr>
<td><div align="center"><?=$objResult ["CustomerID"];?></div></td>
<td><div align="center"><?=$objResult ["logname"];?></div></td>
<td><div align="center"><?=$objResult["password"];?></div></td>
<td><div align="center"><?=$objResult ["name"];?></div></td>
<td><div align="center"><?=$objResult ["gender"];?></div></td>
<td><div align="center"><?=$objResult ["age"];?></div></td>
<td><div align="center"><?=$objResult ["email"];?></div></td>
<td><div align="center"><a href="edit_record_form.php"?CusID="<?=$objResult["CustomerID"];?>">Edit</a></div></td>
</tr>
<?
}
?>
</table>
<?php
mysql_close($objConnect); //ปิดการเชื่อมต่อ
?>
</body>
edit_record_form.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="edit_record_save.php"?CusID=<?=$_GET["CusID"];?>" name="frmEdit" method="post">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("db_drinkup");
$strSQL = "SELECT * FROM userinfo WHERE logname = ' ".$_GET["CusID"]." ' " ;
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found logname=".$_GET["CusID"];
}
else
{
?>
<table width="750" border="0" bgcolor="#CCCCCC">
<tr>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">CustomerID</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">logname</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">password</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">name</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">gender</div></th>
<th width="100"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">age</div></th>
<th width="150"> <div style="background-image:url(image/BG_2.png);color:#FFF;font-weight:bold" align="center">email</div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="txtlogname" size="20" value="<?=$objResult["CustomerID"];?>"></div></td>
<td><div align="center"><input type="text" name="txtlogname" size="20" value="<?=$objResult["logname"];?>"></div></td>
<td><div align="center"><input type="text" name="txtpassword" size="20" value="<?=$objResult["password"];?>"></div></td>
<td><div align="center"><input type="text" name="txtname" size="20" value="<?=$objResult["name"];?>"></div></td>
<td><div align="center"><input type="text" name="txtgender" size="2" value="<?=$objResult["gender"];?>"></div></td>
<td><div align="center"><input type="text" name="txtage" size="5" value="<?=$objResult["age"];?>"></div></td>
<td><div align="center"><input type="text" name="txtemail" size="5" value="<?=$objResult["email"];?>"></div></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<?
}
mysql_close($objConnect);
?>
</form>
</body>
</html>
edit_record_save.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("db_drinkup");
$strSQL = "UPDATE customer SET ";
$strSQL .="CustomerID = '".$_POST["txtCustomerID"]."' ";
$strSQL .=",logname = '".$_POST["txtlogname"]."' ";
$strSQL .=",password = '".$_POST["txtpassword"]."' ";
$strSQL .=",name = '".$_POST["txtname"]."' ";
$strSQL .=",gender = '".$_POST["txtgender"]."' ";
$strSQL .=",age = '".$_POST["txtage"]."' ";
$strSQL .=",email= '".$_POST["txtemail"]."' ";
$strSQL .="WHERE CustomerID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-02-14 22:29:13 |
By :
onekisz |
View :
905 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เมื่อผมกดที่คำว่า delete แล้วเกิดปัญหาตามแบบในรูป ครับ
|
|
|
|
|
Date :
2012-02-14 22:33:00 |
By :
onekisz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ไขนะครับ เมื่อผมกด คำว่า edit แล้ว เป็นแบบในภาพครับ
|
|
|
|
|
Date :
2012-02-14 23:37:23 |
By :
onekisz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<td><div align="center"><a href="edit_record_form.php?CusID=<?=$objResult["CustomerID"]; ?>">Edit</a></div></td>
|
|
|
|
|
Date :
2012-02-15 08:46:52 |
By :
ozma |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|