【发布时间】:2013-04-11 02:22:34
【问题描述】:
我有一个工作表单代码form.php如下:
<?php
//database connection file setting.inc will need to be modified for production
include ("settings.inc");
$db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT DISTINCT `AllianceName`
FROM `City` ORDER BY `AllianceName`
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<html>
<form id='Alliance' name='' method='post' action='results.php'>
<p><label>Alliance Name:</label></p>
<select style="width:300px" class="" id="AllianceName" size="1" name="Alliance">
<?php
while($row = $result->fetch_assoc()){
echo '<option value='.$row['AllianceName'].'>'.$row['AllianceName'].'</option>';
}
?>
</select>
<?php
$sql2 = <<<SQL
SELECT DISTINCT `Continent`
FROM `City` ORDER BY `Continent`
SQL;
if(!$result = $db->query($sql2)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<p><label>Continent:</label></p>
<select style="width:300px" class="" id="Continent" size="1" name="Continent">
<?php
while($row = $result->fetch_assoc()){
echo '<option value='.$row['Continent'].'>'.$row['Continent'].'</option>';
}
?>
</select>
<input type="submit" value="Send" />
</form>
</html>
这会调用 results.php
<?php
include ("settings.inc");
$db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
if(isset($_POST['Alliance']) )
{
$varname = $_POST['Alliance'];
$varcontinent = $_POST['Continent'];
}
echo $_POST['Alliance'];
$sql3 = <<<SQL
SELECT * FROM `City` WHERE `AllianceName` = '$varname'
AND `Continent` = '$varcontinent'
SQL;
if(!$result = $db->query($sql3)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<html>
<?php
while($row = $result->fetch_assoc()){
//arguments etc go here for displaying data in a table
}
?>
现在,我确定 results.php 没问题,因为我已经使用编码的静态查询进行了测试,它从数据库中输出数据。
我的问题很特殊,我还没有找到任何文档来解释为什么会发生这种情况。
在form.php中,选择的联盟值可以是两个或三个单词的字符串。现在这个字符串应该只是解析,但我看到的是它在第一个空格处被截断,即如果字符串是“Have A Nice Day”,我的 $_POST['alliance'] 只会显示“Have”这个词。
我尝试为联盟的选择标签添加一个 length="255" 属性,但这无济于事。
【问题讨论】:
-
引用
<option>标签中的 value 属性。如<option value="I must be quoted!!!">abc</option> -
谢谢。多次搜索,但使用
标签: php html forms http-post form-submit