raghav khanna
raghav khanna

Reputation: 1

$_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>&nbsp;</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">&nbsp;</p>
</div>
<input type="submit" value="SUBMIT ANSWER" />
</form>
</div>
</div>
</div>

THIS IS answer.php and here I try to post information from test2 and test3 fields but I am not getting any output the output shows blank array() and unidentified index test2 and unidentified index test3 I am not able to figure out the error

Upvotes: 0

Views: 159

Answers (3)

clement
clement

Reputation: 4266

You are submitting fields using get

method="GET"

And you SHOULD get the informatiosn trough $_GET['example']; !!!

Example

<form method="post" action="action.php"> 
    text:<input type="text" size =40 name="name"> 
    <input type=submit value="Submit Post"> 
    </form> 

That code inserted into a html page (on the body) represent a form. That form have just one indication, the "text:" and a input where you can put content. When the user is satisfy of its content, he can push the "submit" button (that is representated by the input type = submit in the example). When he press that button, the information included in the input will be give to action.php and that page (coded in the action="action.php") is launched.

Now, in the code of action.php, for example :

<?php echo "The text that you put in the box is : ".$_POST['name']; ?>

If you want to pass the informations trough the URL, you should use GET methods.

<form method="get" action="action.php"> 
    text:<input type="text" size =40 name="name"> 
    <input type=submit value="Submit Post"> 
    </form> 

and in action.php :

<?php echo "The text that you put in the box is : ".$_GET['name']; ?>

I hope that example will open your eyes ;-)

++

Upvotes: 1

sikas
sikas

Reputation: 5523

Change the form method to 'post'.

<form name="answerform" action="answer.php" method="POST">

Upvotes: 1

David Nguyen
David Nguyen

Reputation: 8508

At no point in the code do you even access the POST values of test2 or test3 only test1 which isn't even in your form. Check for $_POST['test2'] and $_POST['test3']

Upvotes: 4

Related Questions