[英]$_POST not working.it ain't producing any values
<?php
$query = "Select * from users where username = '$user' ";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$test = $_POST['test1'];
$ques = "Select * from questions where testname = '$test' ";
$qres = mysql_query($ques) or die(mysql_error());
$qdetails = mysql_fetch_array($qres);
$id = $qdetails['id'];
$testname = $qdetails['testname'];
$ans = "Select * from answers where qid = $id";
$ares = mysql_query($ans) or die(mysql_error());
if($qdetails) {
?>
<div class="padding">
<form name="answerform" action="answer.php" method="GET">
<h3> </h3>
<input name="test2" id="test2" type="text" value="<?php echo $qdetails['testname'];?>" /><h3><?php echo $qdetails['text'];?></h3>
<input name="test3" id="test3" type="text" value="<?php echo $qdetails['testseries'];?>" /><h3><?php echo $qdetails['text'];?></h3>
<br />
<br />
<br />
<?php while($opdetails = mysql_fetch_assoc($ares)) { ?>
<input class="text" id="opt2" name="correctans" type="radio" value="<?php echo $opdetails['text']; ?>" /><br /><?php echo $opdetails['text']; ?> <?php }?>
<div class="two-fields clearfix".
<p class="confirm"> </p>
</div>
<input type="submit" value="SUBMIT ANSWER" />
</form>
</div>
</div>
</div>
這是answer.php,在這里我嘗試發布來自test2和test3字段的信息,但我沒有得到任何輸出,輸出顯示空白array()以及未識別的索引test2和未識別的索引test3我無法找出錯誤
在代碼中的任何時候,您甚至都不會訪問test2
或test3
的POST值,而僅訪問test1
值,而您的表格中甚至沒有。 檢查$_POST['test2']
和$_POST['test3']
您正在使用get提交字段
method="GET"
並且您應該通過$ _GET ['example']獲取信息。 !!!
例
<form method="post" action="action.php">
text:<input type="text" size =40 name="name">
<input type=submit value="Submit Post">
</form>
插入html頁面(在正文中)的代碼代表一種形式。 該表格只有一個指示,即“文本:”和一個可以放置內容的輸入。 當用戶滿意其內容時,他可以按下“提交”按鈕(在示例中由輸入類型=提交表示)。 當他按下該按鈕時,輸入中包含的信息將提供給action.php,然后啟動該頁面(編碼為action =“ action.php”)。
現在,在action.php代碼中,例如:
<?php echo "The text that you put in the box is : ".$_POST['name']; ?>
如果要通過URL傳遞信息,則應使用GET方法。
<form method="get" action="action.php">
text:<input type="text" size =40 name="name">
<input type=submit value="Submit Post">
</form>
並在action.php中:
<?php echo "The text that you put in the box is : ".$_GET['name']; ?>
我希望這個例子會讓你大開眼界;-)
++
將表單方法更改為“ post”。
<form name="answerform" action="answer.php" method="POST">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.