I have a table called Stafflist which is called and lists all of the members on the page.
I then want to have some text boxes for each person which are editable. When the submit button is clicked I want it to insert the staff name and the relevant info from the page into a separate table called ServicesThe code I've got is just pulling at the moment and no inserting is done.
I would be grateful for an example of how to achieve this.
Security isn't an issue right now as I'm going to go through and look at the security part at a later date
<?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</h开发者_运维技巧3></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
}
?>
Thank you in advance for any help
$value1 = mysql_real_escape_string(....
$value2 = mysql_real_escape_string(....
$updateServices = mysql_query('INSERT INTO `Services` (`column1`, `column2`)
VALUES (' . $value1 . ', ' . $value2 . ')');
or, using PHP Data Objects (basic security included, like escaping, type casting)
/**
* @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;
}
精彩评论