下面是我的表单构建,然后是我试图接收数据的PHP脚本。没有值发送,所有变量都保持空白。它不是服务器,因为它有简单的形式在精确的环境中工作。
<table class="addbookings" border="0" cellpadding="2" cellspacing="5">
<th colspan="2" align="center">Add Booking</th>
<form method="post" action="addbooking.php" id="addbookingf">
<tr><td>Forename</td>
<td><input type="text" maxlength="32" name="forename"></td></tr>
<tr><td>Surname</td>
<td><input type="text" maxlength="32" name="surname"></td></tr>
<tr><td>Date</td>
<td><input type="date" name="date"></td></tr>
<tr><td>Start Time</td>
<td><input type="time" step="900" name="stime"></td></tr>
<tr><td>Finish Time</td>
<td><input type="time" step="900" name="ftime"></td></tr>
<tr><td>Contact Number</td>
<td><input type="text" maxlength="14" name="number"></td></tr>
<tr><td>Address</td>
<td><input type="text" maxlength="160" name="address"></td></tr>
<tr><td>Email</td>
<td><input type="text" maxlength="64" name="email"></td></tr>
<tr><td>Quads</td>
<td><input type="number" min="0" max="300" name="quads" value="0"></td></tr>
<tr><td>Clays</td>
<td><input type="number" min="0" max="300" name="clays" value="0"></td></tr>
<tr><td>Archery</td>
<td><input type="number" min="0" max="300" name="archery" value="0"></td></tr>
<tr><td>4x4</td>
<td><input type="number" min="0" max="300" name="4x4" value="0"></td></tr>
<tr><td>MHG</td>
<td><input type="number" min="0" max="300" name="MHG" value="0"></td></tr>
<tr><td>Team Building</td>
<td><input type="number" min="0" max="300" name="TB" value="0"></td></tr>
<tr><td>Treasure Hunt</td>
<td><input type="number" min="0" max="300" name="TH" value="0"></td></tr>
<tr><td>Provisional</td>
<td><input type="checkbox" name="provisional" value="provisional"></td></tr>
<tr><td>Paid Full</td>
<td><input type="checkbox" name="paid" value="paid"></td></tr>
<tr><td>Paid Partial</td>
<td><input type="text" maxlength="12" name="amountpaid" value="0"></td></tr>
<tr><td>Total Cost</td>
<td><input type="text" maxlength="12" name="totalpay" value="0"></td></tr>
<tr><td>Comments</td>
<td><textarea rows="4" name="comment" form="addbookingf">Enter any comments here (eg. disabled)</textarea></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="ADD BOOKING"></td></tr>
</form>
</table>
以下是我收到的addbooking.php
$forename = $surname = $number = $address = $email = $comments = "";
if(isset($_POST['forename'])) $forename = mysql_entities_fix_string($conn,$_POST['forename']);
if(isset($_POST['surname'])) $surname = mysql_entities_fix_string($conn,$_POST['surname']);
if(isset($_POST['date'])) $date = mysql_entities_fix_string($conn,$_POST['date']);
if(isset($_POST['stime'])) $stime = mysql_entities_fix_string($conn,$_POST['stime']);
if(isset($_POST['ftime'])) $ftime = mysql_entities_fix_string($conn,$_POST['ftime']);
if(isset($_POST['number'])) $number = mysql_entities_fix_string($conn,$_POST['number']);
if(isset($_POST['address'])) $address = mysql_entities_fix_string($conn,$_POST['address']);
if(isset($_POST['email'])) $email = mysql_entities_fix_string($conn,$_POST['email']);
if(isset($_POST['quads'])) $quads = $_POST['quads'];
if(isset($_POST['clays'])) $clays = $_POST['clays'];
if(isset($_POST['archery'])) $archery = $_POST['archery'];
if(isset($_POST['4x4'])) $fourbyfour = $_POST['4x4'];
if(isset($_POST['MHG'])) $mhg = $_POST['MHG'];
if(isset($_POST['TB'])) $tb = $_POST['TB'];
if(isset($_POST['TH'])) $th = $_POST['TH'];
if(isset($_POST['provisional'])) $prov = $_POST['provisional'];
if(isset($_POST['paid'])) $paid = mysql_entities_fix_string($conn,$_POST['paid']);
if(isset($_POST['amountpaid'])) $ampaid = mysql_entities_fix_string($conn,$_POST['amountpaid']);
if(isset($_POST['totalpay'])) $total = mysql_entities_fix_string($conn,$_POST['totalpay']);
if(isset($_POST['comments'])) $comments = mysql_entities_fix_string($conn,$_POST['comments']);
答案 0 :(得分:0)
$ _POST值没问题。唯一的问题是你的php函数
mysql_entities_fix_string(); // Undefined function
使用正确的php函数。
答案 1 :(得分:0)
<input type="submit" value="ADD BOOKING">
这需要更改为
<input type="submit" name="send" value="ADD BOOKING">
然后在isset线上你需要添加:
if (isset($_POST['send'])){
//Do something
}