php - mysql关于html和php的问题

标签 php mysql html

我有一个名为 Stafflist 的表,它被调用并列出了页面上的所有成员。
然后我想为每个人提供一些可编辑的文本框。
单击提交按钮时,我希望它将员工姓名和页面中的相关信息插入到名为服务的单独表中

我得到的代码目前只是拉动,没有完成插入。

我将很感激如何实现这一目标的示例。

安全性现在不是问题,因为我稍后会仔细检查安全性部分

<?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 
  }
?>

提前感谢您的帮助

最佳答案

$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;
}

关于php - mysql关于html和php的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6162178/

相关文章:

php - 在框中显示最近的项目

php - 如何在 if 条件下使用数组

mysql - MySQL 中的图像

javascript - html5 获取 00 :00 format? 中的音频持续时间

javascript - Cheerio - 选择多个类别

php - MySQL删除大量行并重新插入新数据而不中断

Phpunit 断言两个数组是否相等

html - 如何使带有复选框的标签起作用?

php - 台湾貌似PHP错误信息

php - 无法更新 InnoDb 中的数据库