开发者

Getting Value of Form Input Php

I have this HTML:

<?php if(!empty($_GET['pID'])) $the_pID = mysql_real_escape_string($_GET['pID']); 
  #echo $the_pID;
?>

<form action="inc/q/prof.php?pID=<?php echo $the_pID; ?>" method="post">            
  <select id="courseInfoDD" name="courseInfoDD" tabindex="1">
    <?php while($row3 = $sth3->fetch(PDO::FETCH_ASSOC)) {
      echo "<option>".$row3['prefix']." ".$row3['code']."</option>"; 
      } echo "</select>"; ?>
  <input type="text" id="addComment" name="addComment" tabindex="3" value="Enter comment" />
  <input type="hidden" name="pID" value="<?php echo $the_pID; ?>">
  <input type="submit" name="submit" id="submit" />
</form> 

THIS PHP:

<?php

$connect = mysql_connect("###", $username, $password) or die ("Error , check your server connection.");
mysql_select_db("###");

//Get data in local variable
if(!empty($_POST['addComment']))
    $INFOO = mysql_real_escape_string($_POST['addComment']);
if(!empty($_POST['pID']))
    $PIDD = mysql_real_escape_string($_POST['pID']);
if(!empty($_POST['courseInfoDD']))
    $COURSEE = mysql_real_escape_string($_POST['courseI开发者_如何学GonfoDD']);

#print_r($_POST);
echo $the_pID;

// check for null values
if (isset($_POST['submit'])) {
  $query="INSERT INTO Comment 
             (info, pID, cID) 
          VALUES
             ('$INFOO','$PIDD','$COURSEE')";
  mysql_query($query)  or die(mysql_error());
  echo "Your message has been received";
}
#else if(!isset($_POST['submit'])){echo "No blank entries";}
#else{echo "Error!";}
?>

I'm trying to get the value of the code:

<select id="courseInfoDD" name="courseInfoDD" tabindex="1">
  <?php while($row3 = $sth3->fetch(PDO::FETCH_ASSOC)) {
  echo "<option>".$row3['prefix']." ".$row3['code']."</option>"; 
  } echo "</select>"; ?>    

And insert it into php variable $COURSEE which is then being inserted above.

Issue

A Zero inserted for this value?? Which means it has nothing to insert, correct?? Anyone see anything


You should add the value attribute in the HTML element of <option> that you generate using PHP so that it is returned to you when you write $_POST['courseInfoDD']

<select name="Mobile" size="3">
    <option value="Nokia">Nokia</option>
    <option value="iPhone">iPhone</option>
    <option value="Android">Android</option>
</select>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜