Jump to content

php POST problem


hojoff79

Recommended Posts

So basically I have a page where I am receiving a post variable to use to bring up database information but then lower on the page, I have another form using the post method to go to another handling page. The problem is, that when the first page receives the post variable from the page before it, then it cannot pass on the post variable in the form at the bottom of the page.

 

I know the recieving the post variable on the same page as putting out a new one is the problem because whenever I load the page without giving it the post variable, even though some parts of the page screw up, the form at the bottom can pass on the POST variable.

 

Is there any reason you cannot recieve a POST variable and send a new one on the same php page???

 

 

Here is a diagram of the flow:

 

-previouspage.php (passes POST variable on to mainpage.php)

 

-mainpage.php (page where the problem occurs, takes the POST variable from previouspage.php and uses it to pull up database information, then has another form at the bottom which sends a new POST variable to lastpage.php)

 

-lastpage.php (DOES NOT take the POST variable from mainpage.php unless mainpage.php did not take the POST variable from previouspage.php)

 

 

Thank you for your help in advance.

 

Here is the code:

 

 

php
session_start();

if (!$_SESSION['valid_user'])
{
$_SESSION['attempt']=1;
Header("Location:index.php");
}

require_once 'database.php';
$dbname = "TextbookInfo";
@mysql_select_db($dbname) or die('Database does not exist');

$user = $_SESSION['valid_user'];
$classnum = $_POST['class'];
$query= "SELECT class, bookname, isbn, requirement, notes FROM textbookinfo WHERE classnum='$classnum'";
$result = mysql_query($query);
mysql_close();


$rows = @mysql_num_rows($result);
$class = mysql_result($result, 0, "class");
echo "Books Assigned for $class<br><br>";


echo '<html>';

echo '<form name="form" method="POST" action="editclasspage.php">';
echo '<input name="hello">';
echo '<input type="submit" name="edit" value="Edit Entry">';
echo '</form>';

echo '</html>';


echo "<br><b>Links</b><br>";
echo '<a href="members.php">Back To Member\'s Homepage</a>';


?>

 

And just to be clear, the variable i can't get to come through to editclasspage.php is the hello variable from the second form.

Link to comment
Share on other sites

I'm not sure exactly what you're asking, but if you're asking which variable I cannot find in the new page, it's the "hello" input from the following form

 

echo '<form name="form" method="POST" action="editclasspage.php">';
echo '<input name="hello">';
echo '<input type="submit" name="edit" value="Edit Entry">';
echo '</form>';

 

Whenever I type something in, it only works if I loaded the page without giving it a $_POST variable from the previous page.  If it has that $_POST variable at the top, then it can't pass on the new variable.  If that wasn't your question I'm sorry, please clarify it and I'll do the best I can to answer it.

Link to comment
Share on other sites

no I'm not trying to have the result from the first form influence the result for the second form at all.  The variable the page receives simply will be used to print a table up above, and then I want the bottom form to be completely independent of the top form, but somehow they are still effected with the code used, I am have simplified the codes greatly and the problem still exists where you cannot have a page receive and send a variable.  Here is the simplified codes (of all 3 pages, that show the problem).

 

test.php, passes along variable hello to test2.php

<?php

echo "<html>";

echo "<form name='hello' method='POST' action='test2.php'>";
echo "Hello Variable <input name='hello'>";
echo "<input type='submit' name='name'>";
echo "</form>";

echo "</html>";

?>

 

test2.php, this should accept the variable from test.php and then have a completely new form to pass on to classeditpage.php

<?php

$status = $_POST['hello'];
echo "$status";


echo '<form name="form" method="POST" action="editclasspage.php">';
echo '<input type= "text" name="hello">';
echo '<input type="submit" value="Edit Entry">';
echo '</form>';

echo '</html>';

?>

 

classeditpage.php this should just take the text variable from test2.php and display it, it only it does not work when test2.php takes the variable from test.php.  If i loadup test2.php without it getting the variable from test.php, then it CAN pass the variable on to this last page classeditpage.php

<?php
session_start();


if (!$_SESSION['valid_user'])
{
$_SESSION['attempt']=1;
Header("Location:index.php");
}
$status = $_POST['hello'];
echo "$status";

?>

<html>
<br>
<br>
<a href="http://www.cashforcritique.com/members.php">Back to Members Page</a>
</html>

 

and the session is definitely not the issue because I just tried it without that, and the variable does exist in sesion (all the other pages with the session check work). Just to be clear that isn't the issue

Link to comment
Share on other sites

So I am kind of surprised that this is such a big issue and that no one has ever run into this problem before.  I just would have expected that taking a variable from a POST on a previous page and using it to display information, then creating a new POST variable based on feedback from that page would be very common.  If no one knows how to do that, then how else would I be able to use a variable to display information on the top of a page then get feedback on the bottom of a page???

Link to comment
Share on other sites

I have also attempted taking everything possible out of the php echo function and just putting it in regular html but that did not help, and like I say i have taken out all the session variables to make it the simplest code possible....stilll the same issue.  This is the last kink in a month month long project which can connect all my pages, so if there is ANY way to do this i'm not looking at I'll take it (or if you see what's wrong with the way I'm doing it).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.