我有这个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>
这个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['courseInfoDD']);
#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!";}
?>
我正在尝试获取代码的值:
<select id="courseInfoDD" name="courseInfoDD" tabindex="1">
<?php while($row3 = $sth3->fetch(PDO::FETCH_ASSOC)) {
echo "<option>".$row3['prefix']." ".$row3['code']."</option>";
} echo "</select>"; ?>
然后将其插入php variable $COURSEE
,然后将其插入上方。
为此值插入零值?这意味着它没有什么可插入的,正确的?任何人都看到了什么
答案 0 :(得分:1)
您应该在使用PHP生成的value
的HTML元素中添加<option>
属性,以便在您编写$_POST['courseInfoDD']
时将其返回给您
<select name="Mobile" size="3">
<option value="Nokia">Nokia</option>
<option value="iPhone">iPhone</option>
<option value="Android">Android</option>
</select>