html 选择不起作用

发布于 2024-11-03 07:53:40 字数 1176 浏览 1 评论 0原文

你好 我绝对被困在这里,我是一名 PHP 程序员,我认为我的 HTML 非常出色,但由于某种原因我被困在这个问题上:

我有一个表单,它有两个选择选项:

<select name="pays">
 <option value ="ireland">Ireland</option>
 <option value ="us">US</option>
</select>
<br>
<select name="carrier">
  <option value="ireland">Irish Network</option>
  <option disabled="disabled"><b>US<b></option>
  <option value="verizon">Verizon</option>
  <option value="sprint">Sprint</option>
  <option value="att">AT&T</option>
  <option value="cellularone">Cellular One</option>
  <option value="nextel">Nextel</option>
  </select>

我的 PHP 文件是这样的:

$country= $_POST['pays'];
$carrier= $_POST['carrier'];

。 ...

$sql="INSERT INTO members (cname, cnumber, country, carrier)
VALUES ('$name', '$number', '$country', '$carrier')";

奇怪的是,值 $name 和 $number 工作正常(它们也是表单中的输入字段),但两个选择选项为空。我已经重复了 $country 和 $Carrier,但它们是空白的,让我认为表格有问题。

有什么想法吗?

PS 没有出现错误

P.PS 如果你不会说法语,则支付=法语国家

谢谢 尼尔

Hi
I am absolutely stuck here, i'm a PHP programmer and i would consider my HTML to be excellent but for some reason i'm stuck on this:

I have a form and it has two select options :

<select name="pays">
 <option value ="ireland">Ireland</option>
 <option value ="us">US</option>
</select>
<br>
<select name="carrier">
  <option value="ireland">Irish Network</option>
  <option disabled="disabled"><b>US<b></option>
  <option value="verizon">Verizon</option>
  <option value="sprint">Sprint</option>
  <option value="att">AT&T</option>
  <option value="cellularone">Cellular One</option>
  <option value="nextel">Nextel</option>
  </select>

My PHP file is this:

$country= $_POST['pays'];
$carrier= $_POST['carrier'];

....

$sql="INSERT INTO members (cname, cnumber, country, carrier)
VALUES ('$name', '$number', '$country', '$carrier')";

The strange thing is that the values $name and $number work fine (they are input fields in the form aswell) but the two select options are empty. I've echoed out the $country and $carrier but they're blank, making me think there is a problem with the form.

Any ideas??

P.S no errors come up

P.P.S if you don't speak french, pays=country in french

Thanks
Niall

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

晨曦÷微暖 2024-11-10 07:53:40

我想到两件事, print_r($_POST) 并查看值是否在 post 中。

标签内的选择框是否表明显而易见但可能是问题?

Two things come to mind, print_r($_POST) and see if the values are in post.

Are the select boxes inside the tag, stating the obvious but could be the issue?

感性 2024-11-10 07:53:40

表格看起来不错。您是否对 $country 和 $carrier 变量执行任何验证?如果您(例如)在连接到数据库之前运行 mysql_real_escape ,那么这可能会导致您描述的问题,其中变量为空。

The form looks OK. Are you performing any validation on the $country and $carrier variables? If you are (for example) running mysql_real_escape before connecting to the database then that can cause the problem you describe, where the variables are blank.

好久不见√ 2024-11-10 07:53:40
<option disabled="disabled"><b>US<b></option>

无效..应该是

<option disabled="disabled"><b>US</b></option>
<option disabled="disabled"><b>US<b></option>

is not valid.. should be

<option disabled="disabled"><b>US</b></option>
孤单情人 2024-11-10 07:53:40

试试这个:

$sql= sprintf("插入成员
(cname、cnumber、国家/地区、运营商)
值('%s'、'%s'、'%s'、'%s')",
$名称,
$数字,
$国家,
$承运人);

这是因为当您执行包含单引号的 SQL 查询时,它不会计算变量,而是直接使用单引号内的值。

Try this:

$sql= sprintf("INSERT INTO members
(cname, cnumber, country, carrier)
VALUES ('%s', '%s', '%s', '%s')",
$name,
$number,
$country,
$carrier );

That's because when you exectue an SQL query with single quotes inside, it will not evaluate the variable, it will literally use the value inside the single quotes.

万水千山粽是情ミ 2024-11-10 07:53:40

您使用了正确的方法(帖子)吗?如果您不指定,将使用$_GET。另外,要在一个表单帖子中同时获取“付款”和“承运人”,它们应该位于相同的

中,请参阅下面的示例代码:

<form method="post">
    <select name="pays">...</select>
    <select name="carrier">...</select>
</form>

Did you use the right method (post)? If you don't specify $_GET will be used. Also to get both "pays" and "carrier" in one form-post they should both be in the same <form> see below example code:

<form method="post">
    <select name="pays">...</select>
    <select name="carrier">...</select>
</form>
瞎闹 2024-11-10 07:53:40

编辑评论:a) 我意识到这离主题太远了,b) 我的代码包含字段集的 CSS。我确实为转移注意力而道歉。 ianm

我在 www.toursbw.net 上有一个 PHP CSS 和 HTML 应用程序。使用演示选项可以访问完整系统。

当我使用三星 Android 智能手机运行此程序时,我的选择框/字段将第一行显示为空白,但是当触摸选择向下箭头时,选择选项将以与键盘相同的方式显示,并且一切正常。它需要由向下箭头触发。

选择书:

function select_book($sid = 0, $debug = false) {

$db = "  ";
$sql = "select confirmed, bkname, bkid, custid, reftype
        from t_book order by confirmed, bkname, bkid"; // id to sequence dups
if ($debug) { echo "<br />fb1030 sql: $sql |<br />"; show_session(); }    
$arr = tdbquery( $sql );
$src =  $_SESSION['rowdb'];
if ($src > 0) {      
     $db .= "<fieldset>     
        <legend>Select a Booking by NAME ($src):</legend>
        --- Sequence is Unconfirmed (Ux) first then Confirmed (Cx). Where 
        x is N for NORMAL I for Person Of Interest C for CLIENT and S for SUBBY.<br />        
        <label for=\"controlinfo\">Booking Ref. Name :</label>         
        <select class=\"formSelect\" name=\"byname\" size=\"10\" >           
           ";
     while ($recs = mysqli_fetch_array($arr)) {
         $id = $recs[bkid]; 

         $st = "("; 
         if ($recs[confirmed] > 0) { $st .= "C"; } else { $st .= "U";};  
         if ($recs[reftype] == 1) { $st .= "I)";}
         elseif ($recs[reftype] == 2) { $st .= "C)";} 
         elseif ($recs[reftype] == 3) { $st .= "S)";} 
         else { $st .= "N)";} 

         $db .= "<option value=\"$id\" ";
         if ($id == $sid )  {                   
            $db .=  " selected > $st -- $recs[bkname] -- (ID:$recs[bkid]) </option>";  
         } else {     
            $db .=  "> $st -- $recs[bkname] -- (ID:$recs[bkid]) </option>";}
         }
    $db .= "
    </select>
    </fieldset>  ";         
} else {
        $db .= "<h4>fb1058 There are no bookings available: </h4>
        ";}
return $db;
}  // end select_book

这是生成选择框/字段的代码。
($debug 代码在外部设置为 ON,在 Smartphoe 上运行时没有显示任何异常。)

希望这有一些用处,ianm

EDit Comment : a) I realsed that this is way off topic and b) my code includes CSS for the fieldset. I do apologise for the red herring. ianm

I have a PHP CSS, and HTML application online at www.toursbw.net . Using the DEMO selection gains access to the FULL SYSTEM.

When I run this using my Samsung Android Smartphone my selection boxes/fields display the first line as blank BUT when the select downarrow is touched the selection options are displayed in the same way as the keyboard and all works fine. It needs to be triggered by the down arrow.

select_book :

function select_book($sid = 0, $debug = false) {

$db = "  ";
$sql = "select confirmed, bkname, bkid, custid, reftype
        from t_book order by confirmed, bkname, bkid"; // id to sequence dups
if ($debug) { echo "<br />fb1030 sql: $sql |<br />"; show_session(); }    
$arr = tdbquery( $sql );
$src =  $_SESSION['rowdb'];
if ($src > 0) {      
     $db .= "<fieldset>     
        <legend>Select a Booking by NAME ($src):</legend>
        --- Sequence is Unconfirmed (Ux) first then Confirmed (Cx). Where 
        x is N for NORMAL I for Person Of Interest C for CLIENT and S for SUBBY.<br />        
        <label for=\"controlinfo\">Booking Ref. Name :</label>         
        <select class=\"formSelect\" name=\"byname\" size=\"10\" >           
           ";
     while ($recs = mysqli_fetch_array($arr)) {
         $id = $recs[bkid]; 

         $st = "("; 
         if ($recs[confirmed] > 0) { $st .= "C"; } else { $st .= "U";};  
         if ($recs[reftype] == 1) { $st .= "I)";}
         elseif ($recs[reftype] == 2) { $st .= "C)";} 
         elseif ($recs[reftype] == 3) { $st .= "S)";} 
         else { $st .= "N)";} 

         $db .= "<option value=\"$id\" ";
         if ($id == $sid )  {                   
            $db .=  " selected > $st -- $recs[bkname] -- (ID:$recs[bkid]) </option>";  
         } else {     
            $db .=  "> $st -- $recs[bkname] -- (ID:$recs[bkid]) </option>";}
         }
    $db .= "
    </select>
    </fieldset>  ";         
} else {
        $db .= "<h4>fb1058 There are no bookings available: </h4>
        ";}
return $db;
}  // end select_book

This is the code that produces the selection box / field.
(The $debug code is set ON externally and showed no abnormalities when run on the Smartphoe.)

Hope this is of some use, ianm

尛丟丟 2024-11-10 07:53:40

您可以使用 $_POST['name'] 从 post 方法获取值。

 <?php
if($_POST){
print_r($_POST);
echo "<br/>";
echo $_POST['pays'];
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="pays">
  <option value ="ireland">Ireland</option>
  <option value ="us">US</option>
</select>
<input type="submit">
</form>

希望对你有帮助!!!

You can use $_POST['name'] to get value from post method.

 <?php
if($_POST){
print_r($_POST);
echo "<br/>";
echo $_POST['pays'];
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="pays">
  <option value ="ireland">Ireland</option>
  <option value ="us">US</option>
</select>
<input type="submit">
</form>

Hope it helps you!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文