0

更新.php

$q = mysql_query("SELECT id FROM performer WHERE username='$user' LIMIT 1") or die("Error : " . mysql_error());
$r = mysql_fetch_assoc($q);
$id = $r['id'];

$query = mysql_query("SELECT baned_c, baned_c2, baned_c3 FROM performer_s WHERE id='$id' LIMIT 1");
$result = mysql_fetch_assoc($query);
if($result['baned_c'] == NULL) { $res1 = "NONE"; } else { $res1 = $result['baned_c']; }

<?php

echo "<form method=post action=insert.php>";

echo "<select name=country>";
echo "<option value=>NONE</option>";
$country = mysql_query("SELECT DISTINCT country_name FROM country_list ORDER BY country_name ASC");
while($next = mysql_fetch_assoc($country))
{
if($next['country_name'] == $res1)
{
    echo "<option selected value=" . $next['country_name'] . ">" .     $next['country_name'] . "</option>";
}
else
{
    echo "<option value=" . $next['country_name'] . ">" . $next['country_name'] . "</option>";
}
}
echo "</select>";
echo "<br /><input type=submit value=Update List />";
echo "</form>";
mysql_close();

插入.php

$country1 = $_POST['country'];
$user = $_SESSION['MM_Username'];
$query = mysql_query("SELECT id FROM performer WHERE username='$user' LIMIT 1") or die("Error : " . mysql_error());
$row = mysql_fetch_assoc($query) or die("Error : " . mysql_error());
$id = $row['id'];
if(isset($country1)) { mysql_query("UPDATE performer_s SET baned_c='$country1' WHERE id='$id'") or die("Error : " . mysql_error()); }

大家好 2,新来的,很高兴见到你。

希望你能帮助我

上面是我的两页 update.php 和 insert.php

我的问题 :

如果 $country1 = $_POST['country']; 是一个单词的国家,一切都很好,但是如果它是一个两个单词的国家,$_POST 只给了我第一个单词

$country1 = $_POST['country'];
if its AMERICA its OK
if its REPUBLIC OF KOREA NOT OK i only get REPUBLIC

我能做些什么 ?

4

1 回答 1

2

尝试改变:

echo "<option value=" . $next['country_name'] . ">" .     $next['country_name'] . "</option>";

为了:

echo "<option value=\"" . $next['country_name'] . "\">" . $next['country_name'] . "</option>";

基本上,您现在正在生成此 HTML:

<option value=REPUBLIC OF KOREA>REPUBLIC OF KOREA</option>

你应该生成这个 HTML:

<option value="REPUBLIC OF KOREA">REPUBLIC OF KOREA</option>

顺便说一句,做同样的事情(添加"s)到另一个echo(那个selected)。

于 2013-11-05T22:07:55.510 回答