2011-05-28 61 views
2

我有一個名爲Stafflist的表,它被調用並列出頁面上的所有成員。
然後我想爲每個可編輯的人設置一些文本框。
當點擊提交按鈕,我希望它插入工作人員的名字,並從網頁上的相關信息到一個單獨的表名爲ServicesMysql html和php問題

我有此刻正剛拉的代碼,沒有插入完成。

我將不勝感激一個如何實現這一目標的例子。

安全不是問題,現在的我會去通過,並期待在安全部分在以後的日子

<?php 
include 'dbc.php'; 

page_protect(); 
company(); 

$stafflist = mysql_query("SELECT * FROM StaffList 
    WHERE full_name != 'Adam Carter' AND full_name != 'Jakata' 
    AND branch = '$_SESSION[branch]' "); 

if (checkAdmin()) { 
?> 

<html><head><title>Book Off Holiday</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<script src="php_calendar/scripts.js" type="text/javascript"></script> 
<link href="styles.css" rel="stylesheet" type="text/css"> 
</head> 

<body> 
<form name="form" action="Newkpi.php" method="post"> 
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> 
<tr> 
<td colspan="3">&nbsp;</td> 
</tr> 
<td width="160" valign="top"> 
<?php 
    if (isset($_SESSION['user_id'])) { 
    } 
?> 
<a href="admin.php">Admin CP </a> 
</td> 
<td width="732" valign="top"> 
<p> 
<h3 class="titlehdr">New KPI</h3> 
<table width="300px" border="0" align="Centre" cellpadding="2" cellspacing="0"> 
<tr bgcolor="#000050"> 

<td width="20px"><h3 class="Text2">Staff Member</h3></td> 
<td width="20px"><h3 class="Text2">Service Amount</h3></td> 
<td width="20px"><h3 class="Text2">Service Date</h3></td> 
<td width="20px"><h3 class="Text2">Forecast For Next Month</h3></td> 
<td width="20px"><h3 class="Text2">Product Sales</h3></td> 
<td width="20px"><h3 class="Text2">Clients This Month</h3></td> 
<td width="20px"><h3 class="Text2">Personel Retension</h3></td> 
<td width="20px"><h3 class="Text2">Total Retension</h3></td> 
<td width="20px"><h3 class="Text2">Colours</h3></td> 
<td width="20px"><h3 class="Text2">Cuts</h3></td> 
<td width="20px"><h3 class="Text2">Pre-Booking</h3></td> 
<td width="20px"><h3 class="Text2">Time Used</h3></td> 

</tr> 

<?php 
    while ($rrows = mysql_fetch_array($stafflist)) { 
?> 
<tr> 
<td name="user_name"><h3 class="Text3"><?php echo $rrows['full_name'];?></h3></td> 
<td><h3 class="Text3"><input name="Serviceamount" type="text" size="4" id="Serviceamount"></h3></td> 
<td><h3 class="Text3"><input name="servicedate" type="text" size="4" id="servicedate"></h3></td> 
<td><h3 class="Text3"><input name="forecast" type="text" size="4" id="forecast"></h3></td> 
<td><h3 class="Text3"><input name="productsales" type="text" size="4" id="productsales"></h3></td> 
<td><h3 class="Text3"><input name="Clientsthismonth" type="text" size="4" id="Clientsthismonth"></h3></td> 
<td><h3 class="Text3"><input name="Personelret" type="text" size="4" id="Personelret"></h3></td> 
<td><h3 class="Text3"><input name="Totalret" type="text" size="4" id="Totalret"></h3></td> 
<td><h3 class="Text3"><input name="colours" type="text" size="4" id="colours"></h3></td> 
<td><h3 class="Text3"><input name="cuts" type="text" size="4" id="cuts"></h3></td> 
<td><h3 class="Text3"><input name="prebooking" type="text" size="4" id="prebooking"></h3></td> 
<td><h3 class="Text3"><input name="timeused" type="text" size="4" id="timeused"></h3></td> 
</tr> 

<?php 
    } 
?> 
</table> 
<input name="doSubmit" type="submit" id="doSubmit" value="Create"> 

</td></table></form></body></html> 
<?php 
    } 
?> 

預先感謝您的任何幫助

+1

「以後再看安全部分」恕我直言,一個不好的主意,會導致無法解釋的錯誤... – feeela 2011-05-28 14:38:28

+0

總是從一開始就建立在安全性上,它不能成爲事後的追求,因爲你會被咬傷! – Johan 2011-05-28 14:44:28

+0

我確實有一個相當不錯的保護頁面功能,它不允許SQL注入並將所有人轉移到登錄頁面,如果沒有登錄 – slowie 2011-05-28 14:46:29

回答

2
$value1 = mysql_real_escape_string(.... 
$value2 = mysql_real_escape_string(.... 
$updateServices = mysql_query('INSERT INTO `Services` (`column1`, `column2`) 
    VALUES (' . $value1 . ', ' . $value2 . ')'); 

,或者使用PHP Data Objects(基本的安全包括,如逸出,壓鑄類)

/** 
* @var PDO $database 
*/ 
$stmt = $database->prepare('INSERT INTO `Services` (`column1`, `column2`) 
    VALUES (:value1, :value2)'); 
$stmt->bindValue(':value1', $value1); 
$stmt->bindValue(':value2', $value2); 
if($stmt->execute() == true && $stmt->rowCount() > 0) 
{ 
    // whatever to do on success 
    return true; 
} 
+0

編輯你的文章以包含'mysql_real_escape_string',所以OP沒有得到他的積極思維會保護他的想法。 – Johan 2011-05-28 14:56:10

+0

您能否更深入地討論這個問題?目前我的查詢拉了14條記錄,但是當我插入它時,只能看到一條記錄,我需要它輸入所有數據14 – slowie 2011-05-28 19:42:00

+0

@slowie在循環中重複整個事情怎麼辦? – feeela 2011-05-31 16:27:03