...

View Full Version : value not being POSTED to next page



woodplease
02-02-2010, 02:59 PM
i have a form where i post values, and then retrieve them on another page, but only one of the values is being retrieved.

This is my post form


<?php
$id = $_GET['id'];
$query = "SELECT * FROM questions WHERE quizref = " .$id ;
$question = 'questionno';
$result2 = pg_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = pg_num_rows($result2);

?>

<form method="post" action ="editquestions.php">
<?PHP

for($i = 1; $i <= $numofrows; $i++) {
$row = pg_fetch_array($result2); //get a row from our result set

echo '<input type="hidden" name="quizno" value="'.$id.'">
<input type="hidden" name="questionno" id="'.$row['questionno'].'" value="'.$row['questionno'].'" >
<br/><p>Question '.$row['questionno'].': ' .$row['question'].' <input type="Submit" id="'.$row['questionno'].'" value="EDIT"> <br/><br/></p>




and this is the code that retrieves it


$id = $_POST['quizno'];
$question = $_POST['questionno'];

echo 'The quiz number is:'.$id;
echo'<br/>The question number is:'.$question;


It is only displaying the $id correctly,and it displays the $question as the total number of questions on the previous page, even though when you view the source, the value that is to be sent is thequestion number.

this is the link to the page that originally posts the information, and then when you click the edit button, it takes you to the page that is supposed to display that information
http://users.aber.ac.uk/agd8/quizdom/questionlist.php?id=1

angst
02-02-2010, 03:08 PM
I've just viewed your source, you've only got one opening form tag in there with many input that have duplicate names. so you'll never get the correct result with this setup.

try adding one form for each block/question.



<?PHP
for($i = 1; $i <= $numofrows; $i++) {
echo "<form method='post' action ='editquestions.php'>";
$row = pg_fetch_array($result2); //get a row from our result set

echo '<input type="hidden" name="quizno" value="'.$id.'">
<input type="hidden" name="questionno" id="'.$row['questionno'].'" value="'.$row['questionno'].'" >
<br/><p>Question '.$row['questionno'].': ' .$row['question'].' <input type="Submit" id="'.$row['questionno']." value="EDIT"> <br/><br/></p>
echo "</form>";
}

masterofollies
02-02-2010, 06:40 PM
When you use a forum, the POST is only given to the next page. You can use SESSION to keep the variable through multiple pages and unset or destory the sessions at the last page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum