开发者

html select not working

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) b开发者_StackOverflow中文版ut 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


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?


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.


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

is not valid.. should be

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


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.


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>


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


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!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜