我有一个名为Stafflist的表,它被调用并列出页面上的所有成员 然后,我希望每个人都有一些可编辑的文本框 单击提交按钮时,我希望它将页面中的人员姓名和相关信息插入一个名为Services
的单独表中。我得到的代码只是拉动,没有插入。
我将很感激如何实现这一目标。
安全性现在不是问题,因为我将在以后查看安全部分
<?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"> </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
}
?>
提前感谢您的任何帮助
答案 0 :(得分: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;
}