我有點迷路了數據庫的新手。我試圖創建一個頁面/表單,從一個只有管理員才能看到的鏈接中,從數據庫中獲取$ id的信息,顯示它以便每個字段都可以更新並保存回數據庫。我還在頁面底部添加了一個表單,以便將新字段輸入到數據庫中。爲了簡單起見,我將它們放在一頁上,但如果需要,我可以將它們分開。我的代碼還沒有工作,任何幫助將不勝感激。MySQL的PHP插入和更新
echo "<a href=\"test.html?p=ID{$row["id"]}\">Edit</a><br>";
吐出連結的test.html P = ID(#) 連桿部分被正常使用。
管理頁面
<div><h1 class="pageTitle">Episode List UPDATE</h1></div>
<?php
// Connect to the database
require 'include/episodelist.db.php';
// Ask the database for the information from the season table BUT how to only get info for the ID?
$query="SELECT * FROM `season` WHERE `id` = $id";
$result = mysql_query("SELECT * FROM season");
$num=mysql_numrows($result);
mysql_close();
?>
<form action="include/epslist.update.php" method="POST">
<table>
<tr>
<td>Season Number: </td><td><input type="text" name="season_sum" size="50" value="<? echo "$season_num";?>"></td>
</tr>
<tr>
<td>Episode Number: </td><td><input type="text" name="eps_num" size="50" value="<? echo "$eps_num";?>"></td>
</tr>
<tr>
<td>Temp Episode Number: </td><td><input type="text" name="temp_eps_num" size="50" value="<? echo "$temp_eps_num";?>"></td>
</tr>
<tr>
<td>Title: </td><td><input type="text" name="title" size="50" value="<? echo "$title";?>"></td>
</tr>
<tr>
<td>Description: </td><td><textarea type="text" name="descrip" cols="50" rows="7" value="<? echo "$descrip";?>"></textarea></td>
</tr>
<tr>
<td colspan="2">
<input type="Submit" value="Update">
</td>
</tr>
</table></form>
<div class="Down10px"></div>
<div><h1 class="pageTitle">Episode List NEW</h1></div>
<form action="include/epslist.new.php" method="POST">
<table>
<tr>
<td>Season Number: </td><td><input type="text" name="season_sum" size="50" value="<? echo "$season_num";?>"></td>
</tr>
<tr>
<td>Episode Number: </td><td><input type="text" name="eps_num" size="50" value="<? echo "$eps_num";?>"></td>
</tr>
<tr>
<td>Temp Episode Number: </td><td><input type="text" name="temp_eps_num" size="50"></td>
</tr>
<tr>
<td>Title: </td><td><input type="text" name="title" size="50"></td>
</tr>
<tr>
<td>Description: </td><td><textarea type="text" name="descrip" cols="50" rows="7"></textarea></td>
</tr>
<tr>
<td colspan="2">
<input type="Submit" value="New Item">
</td>
</tr>
</table></form>
epslist.update.php
<?php
require "episodelist.db.php";
//Test for user inout
if (!empty($_GET[season_sum])&&
!empty($_GET[eps_num])&&
!empty($_GET[temp_eps_num])&&
!empty($_GET[title])&&
!empty($_GET[descrip]))
{
// Im at a lost how to pull in the data just for test.html&=edit(#), check if a user changed it, then if so update that value in the database
// Trying to redirect the user back to the list once the update is finished
header("Location:");
?>
epslist.new.php 修訂
<?php
require "episodelist.db.php";
//Test for user inout
if (!empty($_POST[season_sum])&&
!empty($_POST[eps_num])&&
!empty($_POST[temp_eps_num])&&
!empty($_POST[title])&&
!empty($_POST[descrip]))
{
$season_sum = mysqlclean($_POST,"season_sum",$link);
$eps_num = mysqlclean($_POST,"eps_num",$link);
$temp_eps_num = mysqlclean($_POST,"temp_eps_num",$link);
$title = mysqlclean($_POST,"title",$link);
//This is a text area cols 50 rows 7
$descrip = mysqlclean($_POST,"descrip",$link);
$ID = mysqlclean($_POST,"id",$link);
}
if (! empty($_POST['ID']))
$id = (int)$_POST['ID'];
else $id = 'NULL';
//Insert new entry
$query = "INSERT INTO `season` (`ID`, `season_num`, `temp_eps_num`, `esp_num`, `title`, `descrip`) VALUES ({$id}, '{$season_sum}', '{$eps_num}', '{$temp_eps_num}', '{$title}', '{$descrip}')";
// Trying to rederect the user back to the list once the update is successfully finished
header("Location: episodelist_superadmin.html");
?>
請提出您的問題標題描述的問題,而不是僅僅列出技術。 – 2012-02-29 13:37:13