[請益] PHP表單Update資料庫
小弟現在正在學習用表單來Update資料庫/資料表裡面的資料
我是先用書本上的範例去改,但一直無法成功Update資料表裡的資料
(基本上是可以成功顯示,但是在submit之後雖然會成功跳回指定的頁面但是資料表中的資料
並沒有成功Update)
以下是我寫的PHP(Update的部分),懇請大大們賜教,已經為這個問題試了好一陣子了...
謝謝~!
<?php
include("connMysql.php");
if (!mysql_select_db("mlbdata")) die("fail!");
if(isset($_POST["action"])&&($_POST["action"]=="update")){
$sql_query = "UPDATE `mlbplayers`
SET cName='".$_POST["cName"]."', WHERE cID=".$_POST["cID"];
mysql_query($sql_query);
header("Location:data.php");
}
$sql_db = "SELECT * FROM `mlbplayers` WHERE `cID`=".$_GET["id"];
$result = mysql_query($sql_db);
$row_result=mysql_fetch_assoc($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>playerdata</title>
</head>
<body>
<form action="" method="post" name="formFix" id="formFix">
<table border="1" align="center" cellpadding="4">
<tr>
<th>Table</th><th>data</th>
</tr>
<tr>
<td>Name</td><td><input type="text" name="cName" id="cName" value="<?php echo $row_result["cName"];?>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="cID" type="hidden" value="<?php echo $row_result["cID"];?>">
<input name="action" type="hidden" value="update">
<input type="submit" name="button" id="button" value="sumit">
<input type="reset" name="button2" id="button2" value="reset">
</td>
</tr>
</table>
</form>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.25.212
推
10/02 08:51, , 1F
10/02 08:51, 1F
→
10/02 08:56, , 2F
10/02 08:56, 2F
→
10/02 08:56, , 3F
10/02 08:56, 3F
→
10/02 08:57, , 4F
10/02 08:57, 4F
推
10/02 15:58, , 5F
10/02 15:58, 5F
→
10/02 15:59, , 6F
10/02 15:59, 6F
→
10/04 07:42, , 7F
10/04 07:42, 7F