2011-05-28 60 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