我有一个网站,其表单应允许人们添加多个请假日期。我试图给一个特定的人添加一个以上的休假日期,但不能让它工作。我有两个表志愿者,我在这里工作,我可以从网站添加新的志愿者,并在sql数据库中更新,只需要志愿者休假。
CREATE TABLE [VOLUNTEER](
[VOLUNTEER_ID] [int] identity (1,1) not null,
[FIRSTNAME] [nvarchar] (20) not null,
[LASTNAME] [nvarchar] (20) not null,
[DATE_OF_BIRTH] [DATE] NOT NULL,
[PHONENUMBER] [nvarchar] (20) not null,
[ADDRESS] [NVARCHAR] (200) NOT NULL
);
INSERT INTO [VOLUNTEER](
[FIRSTNAME],[LASTNAME],[DATE_OF_BIRTH],[PHONENUMBER],[ADDRESS])
VALUES
('Randolph','Spinks','1989/09/13','8486463',
'16, Camesky Rd, Caol, Fort William, PH33 7ER'),
('Pete','Cremer','1981/01/24','4178846',
'1, Achintore Rd, Banavie, Fort William, PH33 7RE'),
('Nikia','Norsworthy','1974/06/17','9824814',
'2, Seaview Terrace, Ballachulish, Fort William, PH33 6RG'),
create table [LEAVE](
[LEAVE_ID] [int] identity (1,1) not null,
[VOLUNTEER_ID] [INT] NOT NULL,
[FIRSTNAME] [nvarchar] (20) not null,
[LASTNAME] [nvarchar] (20) not null,
[START_DATE] [DATE] not null,
[END_DATE] [DATE] not null,
);
INSERT INTO [LEAVE]
([VOLUNTEER_ID],[FIRSTNAME],[LASTNAME],[START_DATE],[END_DATE])
VALUES
('1','Randolph','Spinks','2016-08-20','2016-08-23'),
('2','Pete','Cremer','2016-07-20','2016-07-26'),
('3','Nikia','Norsworthy','2016-05-08','2016-06-01')
GO
以下是我在记事本中使用的代码。我不确定名字应该只是一个下拉框,因为他们已经是注册志愿者。我也不知道是否应该包括志愿者ID,这是一个int非空外键字段,将两个表志愿者联系起来并留在一起。
<form name="submit" method="post" >
<h2>Submit Leave</h2>
<table border="0">
<tr>
<td>VOLUNTEER_ID</td>
<td>
<input type="INT" name="VOLUNTEER_ID" id="VOLUNTEER_ID"/>
</td>
</tr>
<tr>
<td>FIRSTNAME</td>
<td>
<select name="FIRSTNAME" id="FIRSTNAME">
<option value="Randolph ">Randolph </option>
<option value="Pete ">Pete </option>
<option value="Nikia ">Nikia </option>
</select>
</td>
</tr>
<tr>
<td>LASTNAME</td>
<td>
<select name="LASTNAME" id="LASTNAME">
<option value=" Spinks "> Spinks </option>
<option value=" Cremer"> Cremer</option>
<option value=" Norsworthy"> Norsworthy</option>
</select>
</td>
</tr>
<tr>
<td>START_DATE</td>
<td>
<input type="DATE" name="START_DATEDATE" id="START_DATE"/>
</td>
</tr>
<tr>
<td>END_DATE</td>
<td>
<input type="DATE" name="END_DATEDATE" id="END_DATE"/>
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit"
value="Submit Leave"/></td>
</tr>
</table>
这里的Apoligies是我的PHP链接他们两个。
<?php
if( !empty( $_POST ) && isset( $_POST["VOLUNTEER_ID"],
$_POST["FIRSTNAME"], $_POST["LASTNAME"], $_POST["START_DATE"],
$_POST["END_DATE"] ) ) {
/*
There is no point creating a db connection if a later condition fails
so create the db conn after testing key variables are set
*/
$server = "KATIE-PC\SQLEXPRESS";
$options = array( "Database"=>"PROJECT2" );
$conn = sqlsrv_connect( $server, $options );
/* In production environment do not display actual errors! */
if( !$conn ) die( print_r( sqlsrv_errors(), true ) );
$VOLUNTEER_ID = $_POST["VOLUNTEER_ID"];
$FIRSTNAME = $_POST["FIRSTNAME"];
$LASTNAME = $_POST["LASTNAME"];
$START_DATE = $_POST["START_DATE"];
$END_DATE = $_POST["END_DATE"];
$sql = "INSERT INTO LEAVE
( [VOLUNTEER_ID],[FIRSTNAME], [LASTNAME], [START_DATE], [END_DATE] )
VALUES
( ?,?,?,?,? )";
$params=array(
&$VOLUNTEER_ID,
&$FIRSTNAME,
&$LASTNAME,
&$START_DATE,
&$END_DATE
);
/* add the posted variables as an array here as the third arg */
$stmt = sqlsrv_prepare( $conn, $sql, $params ) or die( 'Error querying MSSQL database' );
if( $stmt ) sqlsrv_execute( $stmt );
/* debug post vars */
} else {
echo 'Error::' . print_r( $_POST, true );
}
&GT;