史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 論壇程式討論區
忘記密碼?
論壇說明 標記討論區已讀

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2010-01-31, 09:26 PM   #1
tsjms
註冊會員
榮譽勳章
UID - 227607
在線等級: 級別:7 | 在線時長:92小時 | 升級還需:4小時級別:7 | 在線時長:92小時 | 升級還需:4小時
註冊日期: 2006-02-28
VIP期限: 2010-06
住址: 台灣省南部
文章: 16
精華: 0
現金: 19 金幣
資產: 19 金幣
預設 疑問 - php表單關於日期、刪除資料的問題

因為我不是唸資管系畢業,在工作的需求,主管叫我架的php網站...
對php不是很瞭解
日期的問題,填寫表單,不要輸入日期,要自動輸入日期,怎麼設定
我不會修改><,試過了失敗好幾次。
還有,勾選複選項目的問題,勾選好了以後傳送出去,但顯示只1個項目
刪除幾列筆,按刪除之後出現錯誤
麻煩大家幫我看一下,哪裡要修改,謝謝~

SQL:
CREATE TABLE `staff` (
`cID` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`cDep` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`cControl` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`cDate` datetime NOT NULL,
`cDemo` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
`cVer1` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`cNote` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`cVer2` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`cID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=27 ;

connMysql.php
<?php
//資料庫主機設定
$db_host = "localhost";
$db_username = "root";
$db_password = "*****";
//連線伺服器
$db_link = @mysql_connect($db_host, $db_username, $db_password);
if (!$db_link) die("資料連結失敗!");
//設定字元集與連線校對
mysql_query("SET NAMES 'utf8'");

add.php
<?php
if(isset($_POST["action"])&&($_POST["action"]=="add")){
include("connMysql.php");
if (!@mysql_select_db("school")) die("資料庫選擇失敗!");
$sql_query = "INSERT INTO `staff` (`cDate` ,`cDep` ,`cControl` ,`cDemo` ,`cVer1` ,`cVer2` ,`cNote`) VALUES (";
$sql_query .= "'".$_POST["cDate"]."',";
$sql_query .= "'".$_POST["cDep"]."',";
$sql_query .= "'".$_POST["cControl"]."',";
$sql_query .= "'".$_POST["cDemo"]."',";
$sql_query .= "'".$_POST["cVer1"]."',";
$sql_query .= "'".$_POST["cVer2"]."',";
$sql_query .= "'".$_POST["cNote"]."')";
mysql_query($sql_query);
//重新導向回到主畫面
header("Location: data.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>資料管理系統</title>
</head>
<body>
<h1 align="center">新增資料</h1>
<p align="center"><a href="data.php">回主畫面</a></p>
<form action="" method="post" name="formAdd" id="formAdd">
<table border="1" align="center" cellpadding="4">
<tr>
<th>欄位</th><th>資料</th>
</tr>
<tr>
<td>日期</td>
<td><input type="text" name="cDate" id="cDate">
</tr>
<tr>
<td>系名</td>
<td>
<p>
<input type="radio" name="cDep" id="radio" value="A系" checked>
A系
<input type="radio" name="cDep" id="radio" value="B系">
B系

<input type="radio" name="cDep" id="radio" value="C系">
C系</td>
</tr>
<tr>
<td>檢核項目</td>
<td><label>
<input name="cControl" type="checkbox" id="cControl" value="甲">
甲 <input name="cControl" type="checkbox" id="cControl2" value="乙">

<input name="cControl" type="checkbox" id="cControl3" value="丙">

<br>
</label></td>
</tr>
<tr>
<td>上傳資料</td>
<td><input type="radio" name="cDemo" id="radio" value="完成">
完成
<input type="radio" name="cDemo" id="radio" value="未完成">
未完成 </td>
</tr>
<tr>
<td>老師審查</td>
<td><input type="radio" name="cVer1" id="radio" value="審查通過">
審查通過
<input type="radio" name="cVer1" id="radio" value="審查不通過">
審查不通過 </td>
</tr>
<tr>
<td>主管審查</td>
<td><input type="radio" name="cVer2" id="radio" value="審查通過">
審查通過
<input type="radio" name="cVer2" id="radio" value="審查不通過">
審查不通過 </td>
</tr>
<tr>
<td>備註</td>
<td><textarea name="cNote" cols="50" rows="4" id="cNote"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="action" type="hidden" value="add">
<input type="submit" name="button" id="button" value="新增資料">
<input type="reset" name="button2" id="button2" value="重新填寫"> </td>
</tr>
</table>
</form>
</body>
</html>

data.php
<?php
header("Content-Type: text/html; charset=utf-8");
include("connMysql.php");
$seldb = @mysql_select_db("school");
if (!$seldb) die("資料庫選擇失敗!");
$sql_query = "SELECT * FROM `staff`";
$result = mysql_query($sql_query);
$total_records = mysql_num_rows($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>料管理系統</title>
</head>
<body>
<h1 align="center">資料管理系統</h1>
<p align="center">目前資料筆數:<?php echo $total_records;?>,<a href="add.php">新增檢核資料</a>。</p>
<table border="1" align="center">
<!-- 表格表頭 -->
<tr>
<th>編號</th>
<th>日期</th>
<th>系名</th>
<th>項目</th>
<th>上傳資料</th>
<th>老師審查</th>
<th>主管處審查</th>
<th>備註</th>
<th>功能</th>
</tr>
<!-- 資料內容 -->
<?php
while($row_result=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$row_result["cID"]."</td>";
echo "<td>".$row_result["cDate"]."</td>";
echo "<td>".$row_result["cDep"]."</td>";
echo "<td>".$row_result["cControl"]."</td>";
echo "<td>".$row_result["cDemo"]."</td>";
echo "<td>".$row_result["cVer1"]."</td>";
echo "<td>".$row_result["cVer2"]."</td>";
echo "<td>".$row_result["cNote"]."</td>";
echo "<td><a href='update.php?id=".$row_result["cID"]."'>修改</a> ";
echo "<a href='delete.php?id=".$row_result["cID"]."'>刪除</a></td>";
echo "</tr>";
}
?>
</table>
</body>
</html>

data_page.php
<?php
header("Content-Type: text/html; charset=utf-8");
include("connMysql.php");
$seldb = @mysql_select_db("school");
if (!$seldb) die("資料庫選擇失敗!");

//預設每頁筆數
$pageRow_records = 3;
//預設頁數
$num_pages = 1;
//若已經有翻頁,將頁數更新
if (isset($_GET['page'])) {
$num_pages = $_GET['page'];
}
//本頁開始記錄筆數 = (頁數-1)*每頁記錄筆數
$startRow_records = ($num_pages -1) * $pageRow_records;
//未加限制顯示筆數的SQL敘述句
$sql_query = "SELECT * FROM `staff`";
//加上限制顯示筆數的SQL敘述句,由本頁開始記錄筆數開始,每頁顯示預設筆數
$sql_query_limit = $sql_query." LIMIT ".$startRow_records.", ".$pageRow_records;
//以加上限制顯示筆數的SQL敘述句查詢資料到 $result 中
$result = mysql_query($sql_query_limit);
//以未加上限制顯示筆數的SQL敘述句查詢資料到 $all_result 中
$all_result = mysql_query($sql_query);
//計算總筆數
$total_records = mysql_num_rows($all_result);
//計算總頁數=(總筆數/每頁筆數)後無條件進位。
$total_pages = ceil($total_records/$pageRow_records);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>資料管理系統</title>
</head>
<body>
<h1 align="center">資料管理系統</h1>
<p align="center">目前資料筆數:<?php echo $total_records;?>,<a href="add.php">新增檢核資料</a>。</p>
<table border="1" align="center">
<!-- 表格表頭 -->
<tr>
<th>編號</th>
<th>日期</th>
<th>單位</th>
<th>檢核項目</th>
<th>上傳資料</th>
<th>老師審查</th>
<th>主管審查</th>
<th>備註</th>
<th>功能</th>
</tr>
<!-- 資料內容 -->
<?php
while($row_result=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$row_result["cID"]."</td>";
echo "<td>".$row_result["cDate"]."</td>";
echo "<td>".$row_result["cDep"]."</td>";
echo "<td>".$row_result["cControl"]."</td>";
echo "<td>".$row_result["cDemo"]."</td>";
echo "<td>".$row_result["cVer1"]."</td>";
echo "<td>".$row_result["cVer2"]."</td>";
echo "<td>".$row_result["cNote"]."</td>";
echo "<td><a href='update.php?id=".$row_result["cID"]."'>修改</a> ";
echo "<a href='delete.php?id=".$row_result["cID"]."'>刪除</a></td>";
echo "</tr>";
}
?>
</table>
<table border="0" align="center">
<tr>
<?php if ($num_pages > 1) { // 若不是第一頁則顯示 ?>
<td><a href="data_page.php?page=1">第一頁</a></td>
<td><a href="data_page.php?page=<?php echo $num_pages-1;?>">上一頁</a></td>
<?php } ?>
<?php if ($num_pages < $total_pages) { // 若不是最後一頁則顯示 ?>
<td><a href="data_page.php?page=<?php echo $num_pages+1;?>">下一頁</a></td>
<td><a href="data_page.php?page=<?php echo $total_pages;?>">最後頁</a></td>
<?php } ?>
</tr>
</table>
<table border="0" align="center">
<tr>
<td>
頁數:
<?php
for($i=1;$i<=$total_pages;$i++){
if($i==$num_pages){
echo $i." ";
}else{
echo "<a href=\"data_page.php?page=$i\">$i</a> ";
}
}
?>
</td>
</tr>
</table>
</body>
</html>

update.php
<?php
include("connMysql.php");
if (!@mysql_select_db("school")) die("資料庫選擇失敗!");
if(isset($_POST["action"])&&($_POST["action"]=="update")){
$sql_query = "UPDATE `staff` SET ";
$sql_query .= "`cDate`='".$_POST["cDate"]."',";
$sql_query .= "`cDep`='".$_POST["cDep"]."',";
$sql_query .= "`cControl`='".$_POST["cControl"]."',";
$sql_query .= "`cDemo`='".$_POST["cDemo"]."',";
$sql_query .= "`cVer1`='".$_POST["cVer1"]."',";
$sql_query .= "`cVer2`='".$_POST["cVer2"]."',";
$sql_query .= "`cNote`='".$_POST["cNote"]."' ";
$sql_query .= "WHERE `cID`=".$_POST["cID"];
mysql_query($sql_query);
//重新導向回到主畫面
header("Location: data.php");
}
$sql_db = "SELECT * FROM `staff` 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>資料管理系統</title>
</head>
<body>
<h1 align="center">資料管理系統 - 修改資料</h1>
<p align="center"><a href="data.php">回主畫面</a></p>
<form action="" method="post" name="formFix" id="formFix">
<table border="1" align="center" cellpadding="4">
<tr>
<th>欄位</th><th>資料</th>
</tr>
<tr>
<td>日期</td>
<td><input type="text" name="cDate" id="cDate" value="<?php echo $row_result["cDate"];?>"></td>
</tr>
<tr>
<td>單位</td>
<td>
<p>
<input type="radio" name="cDep" id="radio" value="A系" <?php if($row_result["cDep"]=="A系") echo "checked";?>>
A系
<input type="radio" name="cDep" id="radio" value="B系" <?php if($row_result["cDep"]=="B系") echo "checked";?>>
B系
<input type="radio" name="cDep" id="radio" value="C系" <?php if($row_result["cDep"]=="C系") echo "checked";?>>
C系</td>
</tr>
<tr>
<td>檢核項目</td>
<td><input name="cControl" type="checkbox" id="cControl" value="甲"<?php if($row_result["cControl"]=="甲") echo "checked";?>>

<input name="cControl" type="checkbox" id="cControl" value="乙"<?php if($row_result["cControl"]=="乙") echo "checked";?>>
乙<input name="cControl" type="checkbox" id="cControl" value="丙"<?php if($row_result["cControl"]=="丙") echo "checked";?>>
丙 </td>
</tr>
<tr>
<td>上傳資料</td>
<td><input type="radio" name="cDemo" id="radio" value="完成" <?php if($row_result["cDemo"]=="完成") echo "checked";?>>
完成
<input type="radio" name="cDemo" id="radio" value="未完成" <?php if($row_result["cDemo"]=="未完成") echo "checked";?>>
未完成</td>
</tr>
<tr>
<td>老師審查</td>
<td><input type="radio" name="cVer1" id="radio" value="審查通過" <?php if($row_result["cVer1"]=="審查通過") echo "checked";?>>
審查通過
<input type="radio" name="cVer1" id="radio" value="審查不通過" <?php if($row_result["cVer1"]=="審查不通過") echo "checked";?>>
審查不通過</td>
</tr>
<tr>
<td>主管審查</td>
<td><input type="radio" name="cVer2" id="radio" value="審查通過" <?php if($row_result["cVer2"]=="審查通過") echo "checked";?>>
審查通過
<input type="radio" name="cVer2" id="radio" value="審查不通過" <?php if($row_result["cVer2"]=="審查不通過") echo "checked";?>>
審查不通過 </td>
</tr>
<tr>
<td>備註</td>
<td><input name="cNote" type="text" id="cNote" size="40" value="<?php echo $row_result["cNote"];?>"></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="更新資料">
<input type="reset" name="button2" id="button2" value="重新填寫"> </td>
</tr>
</table>
</form>
</body>
</html>

delete.php
<?php
include("connMysql.php");
if (!@mysql_select_db("school")) die("資料庫選擇失敗!");
if(isset($_POST["action"])&&($_POST["action"]=="delete")){
$sql_query = "DELETE FROM `staff` WHERE `cID`=".$_POST["cID"];
mysql_query($sql_query);
//重新導向回到主畫面
header("Location: data.php");
}
$sql_db = "SELECT * FROM `students` 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>資料管理系統</title>
</head>
<body>
<h1 align="center">資料管理系統 - 刪除資料</h1>
<p align="center"><a href="data.php">回主畫面</a></p>
<form action="" method="post" name="formDel" id="formDel">
<table border="1" align="center" cellpadding="4">
<tr>
<th>欄位</th><th>資料</th>
</tr>
<tr>
<td>日期</td>
<td><?php echo $row_result["cDate"];?></td>
</tr>
<tr>
<td>單位</td>
<td>
<?php
if($row_result["cDep"]=="A系"){
echo "A系";
}else{
echo "B系";
}else{
echo "C系";
}
?> </td>
</tr>
<tr>
<td>檢核項目</td>
<td><?php echo $row_result["cControl"];?></td>
</tr>
<tr>
<td>上傳資料</td>
<td><?php echo $row_result["cDemo"];?></td>
</tr>
<tr>
<td>老師審查</td>
<td><?php echo $row_result["cVer1"];?></td>
</tr>
<tr>
<td>主管審查</td>
<td><?php echo $row_result["cVer2"];?></td>
</tr>
<tr>
<td>備註</td>
<td><?php echo $row_result["cNote"];?></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="delete">
<input type="submit" name="button" id="button" value="確定刪除這筆資料嗎?"> </td>
</tr>
</table>
</form>
</body>
</html>
tsjms 目前離線  
送花文章: 2, 收花文章: 2 篇, 收花: 3 次
回覆時引用此帖
舊 2010-02-01, 09:01 AM   #2 (permalink)
註冊會員
榮譽勳章

勳章總數
UID - 335908
在線等級: 級別:2 | 在線時長:12小時 | 升級還需:9小時級別:2 | 在線時長:12小時 | 升級還需:9小時
註冊日期: 2010-01-22
文章: 15
精華: 0
現金: 40 金幣
資產: 140 金幣
預設 修改 input 的內容試試...

提供一種方式....
將下列code...
<tr>
<td>日期</td>
<td><input type="text" name="cDate" id="cDate">
</tr>

改為...

<tr>
<td>日期</td>
<td><input type="text" name="cDate" id="cDate" value="<?php echo date('Y-m-d h:i:s');?>" readonly />
</tr>

試試看~!

======

說明:
1)PHP裡面的date()函式可以將指定的timestamp轉成格式化時間,像 date('Y-m-d h:i:s'); 的結果就是列出當前時間....例如 2010-02-01 09:01:23
如果希望只秀出日期,則改成 date('Y-m-d'); 即可....

2)在<input type="text" ... /> 裡面加上一個 readonly 的屬性,請輸入框變成唯讀狀態,可以確保user不能更改日期這一個欄位。

=====

希望合用喔~!
ccutmis 目前離線  
送花文章: 0, 收花文章: 12 篇, 收花: 17 次
回覆時引用此帖
發文 回覆


主題工具
顯示模式

發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用

相似的主題
主題 主題作者 討論區 回覆 最後發表
關於刪除XP修正包的問題... 小豬喵 一般電腦疑難討論區 1 2003-11-22 01:13 AM
關於asp連結資料庫的問題 薰衣草^^ 一般電腦疑難討論區 1 2003-07-02 06:00 PM
有關於"資料夾"的問題 Kuku 軟體應用問題討論區 7 2003-06-28 05:56 PM
關於 PHP 留言版程式的問題 Iris 軟體應用問題討論區 0 2003-04-12 11:28 AM
有關於win2000資料夾的問題? alucard 軟體應用問題 Q & A 精華區 2 2002-12-23 09:11 PM


所有時間均為台北時間。現在的時間是 06:39 PM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1