大家好我创建了一个包含表单和<select>
标签的表格。我按下提交按钮我想将数据保存到txt文件。然后从txt文件我想加载保存数据。请告诉我们我做错了什么:(
这是原始表格,其格式为:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Stodola</title>
</head>
<body>
<div style="text-align: center;">Stodola</div>
<br>
<form method="post" action="jul.php" name="1">
<table style="text-align: left; width: 100%;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>Dátum</td>
<td>Deň</td>
<td>Čas</td>
<td>Hlavný čašník</td>
<td>Čas</td>
<td>Čašník výpomoc</td>
<td>Čas</td>
<td>Hlavný kuchár</td>
<td>Čas</td>
<td>Pomocné kuchárky</td>
<td>Čas</td>
<td>Prevádzkar</td>
<td>Extra Čašník</td>
<td>Čas</td>
<td>Extra kuchyňa</td>
</tr>
<tr>
<td>1/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<select name="1">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
<br>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>2/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<select name="2">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>3/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<select name="3">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>4/7/2017</td>
<td>Utorok</td>
<td>10:00 - 22:00</td>
<td>
<select name="4">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>5/7/2017</td>
<td>Streda</td>
<td>10:00 - 22:00</td>
<td>
<select name="5">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>6/7/2017</td>
<td>Štvrtok</td>
<td>10:00 - 22:00</td>
<td>
<select name="6">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>7/7/2017</td>
<td>Piatok</td>
<td>10:00 - 22:00</td>
<td>
<select name="7">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>8/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<select name="8">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>9/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<select name="9">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>10/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<select name="10">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>11/7/2017</td>
<td>Utorok</td>
<td>10:00 - 22:00</td>
<td>
<select name="11">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>12/7/2017</td>
<td>Streda</td>
<td>10:00 - 22:00</td>
<td>
<select name="12">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>13/7/2017</td>
<td>Štvrtok</td>
<td>10:00 - 22:00</td>
<td>
<select name="13">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>14/7/2017</td>
<td>Piatok</td>
<td>10:00 - 22:00</td>
<td>
<select name="14">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>15/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<select name="15">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>16/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<select name="16">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>17/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<select name="17">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>18/7/2017</td>
<td>Utorok</td>
<td>10:00 - 22:00</td>
<td>
<select name="18">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>19/7/2017</td>
<td>Streda</td>
<td>10:00 - 22:00</td>
<td>
<select name="19">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>20/7/2017</td>
<td>Štvrtok</td>
<td>10:00 - 22:00</td>
<td>
<select name="20">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>21/7/2017</td>
<td>Piatok</td>
<td>10:00 - 22:00</td>
<td>
<select name="21">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>22/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<select name="22">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>23/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<select name="23">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>24/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<select name="24">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>25/7/2017</td>
<td>Utorok</td>
<td>10:00 - 22:00</td>
<td>
<select name="25">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/7/2017</td>
<td>Streda</td>
<td>10:00 - 22:00</td>
<td>
<select name="26">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>27/7/2017</td>
<td>Štvrtok</td>
<td>10:00 - 22:00</td>
<td>
<select name="27">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>28/7/2017</td>
<td>Piatok</td>
<td>10:00 - 22:00</td>
<td>
<select name="28">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>29/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<select name="29">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>30/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<select name="30">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>31/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<select name="31">
<option>vyber</option>
<option>Lenka</option>
<option>Katka</option>
<option>Maťo</option>
<option>Lubo</option>
</select>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<input name="submit" type="submit">
</form>
<br>
</body>
</html>
这是jul.php
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Stodola</title>
</head>
<body>
<div style="text-align: center;">Stodola</div>
<br>
<table style="text-align: left; width: 100%;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>Dátum</td>
<td>Deň</td>
<td>Čas</td>
<td>Hlavný čašník</td>
<td>Čas</td>
<td>Čašník výpomoc</td>
<td>Čas</td>
<td>Hlavný kuchár</td>
<td>Čas</td>
<td>Pomocné kuchárky</td>
<td>Čas</td>
<td>Prevádzkar</td>
<td>Extra Čašník</td>
<td>Čas</td>
<td>Extra kuchyňa</td>
</tr>
<tr>
<td>1/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["1"]; ?>
<br>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>2/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["2"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>3/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["3"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>4/7/2017</td>
<td>Utorok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["4"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>5/7/2017</td>
<td>Streda</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["5"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>6/7/2017</td>
<td>Štvrtok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["6"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>7/7/2017</td>
<td>Piatok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["7"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>8/7/2017</td>
<td>Sobota</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["8"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>9/7/2017</td>
<td>Nedeľa</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["9"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>10/7/2017</td>
<td>Pondelok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["10"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>11/7/2017</td>
<td>Utorok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["11"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>12/7/2017</td>
<td>Streda</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["12"]; ?>
</td>
<td>10:00 - 22:00</td>
<td></td>
<td>10:00 - 22:00</td>
<td></td>
<td>8:00 - 22:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>13/7/2017</td>
<td>Štvrtok</td>
<td>10:00 - 22:00</td>
<td>
<?php echo $_POST["13"]; ?>
答案 0 :(得分:0)
以下是HTML的外观:
x = script1.function()
和你的php文件:
<form action="**php file path goes here**" method="POST">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>
注意:此答案来自PHP write file from input to txt,因此请在再次询问之前进行检查。
答案 1 :(得分:0)
我可以添加一些细节吗?不要将提交按钮命名为提交。使用name =“subSavetoFile”这样的名称并添加一个id值,如id =“subSavetoFile”。您最终可能会有多个提交按钮,并且您需要使用JavaScript表格检查功能和PHP逻辑来辨别您要执行的操作并进行检查。
不要忘记添加PHP数据检查保护,如intval(),floatval(),mysqli_real_escape_string(),filter_var(),或者有一个已批准的值列表来消除潜在的攻击。</ p>