我正在将表单发送到 php 页面,然后将其保存到 mysql 数据库中。代码似乎执行没有错误,但没有值保存到数据库中。
我是否错过了代码中的某些内容?
形式:
<form action="newcourse.php" method="post">
<input name="title" type="text" id="title" value="">
<br /><br />
<input name="location" type="text" id="location" value="">
<br /><br />
<input name="datestart" type="text" id="datestart" value="">
<br /><br />
<input name="dateend" type="text" id="dateend" value=""><br /><br />
<select name="noofweeks" id="noofweeks">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select><br /><br />
<select name="wheelchair" id="wheelchair">
<option value="yes">yes</option>
<option value="no" selected>no</option>
</select>
<br /><br />
<input name="time" type="text" id="time" value=""><br /><br />
<input name="courseleader" type="text" id="courseleader" value=""><br /><br />
<input name="pack" type="hidden" id="pack" value="participants_pack.pdf">
<input name="price" type="text" id="price" value=""><br /><br />
<input name="group" type="text" id="group" value=""><br /><br />
<input name="numberofplaces" type="text" id="numberofplaces" value=""><br /><br />
<select name="bookings" id="bookings">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="0" selected>0</option>
</select>
<br /><br />
<br /><br />
<input name="submit" type="submit" value="Save"></p></form>
保存到mysql数据库:
<?php
$title=$_POST['title'];
$location=$_POST['location'];
$datestart=$_POST['datestart'];
$dateend=$_POST['dateend'];
$noofweeks=$_POST['noofweeks'];
$wheelchair=$_POST['wheelchair'];
$time=$_POST['time'];
$courseleader=$_POST['courseleader'];
$pack=$_POST['pack'];
$price=$_POST['price'];
$group=$_POST['group'];
$numberofplaces=$_POST['numberofplaces'];
$bookings=$_POST['bookings'];
//
require_once('connecttodatabase.php');
//
mysql_query("INSERT INTO courses (title, location, datestart, dateend, noofweeks, wheelchair, time, courseleader, pack, price, group, numberofplaces, bookings) VALUES('$title', '$location', '$datestart', '$dateend', '$noofweeks', '$wheelchair', '$time', '$courseleader', '$pack', '$price', '$group', '$numberofplaces', '$bookings')");
mysql_close();
echo "Database updated!";
?>
connecttodatabase.php 只是连接到数据库并适用于其他脚本,所以我知道这不是问题。