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>';


?>

Link to comment
Share on other sites

Hi, I presume from your code that you are refferring to the $_POST['class']

 

If you are refferring to this form (that goes to editclass.php):

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

You haven't actually included the field and value in the form.

You need to add a hidden form field like this:

echo '<input type="hidden" name="class" value="'.$_POST["class"].'">';

Chris

Link to comment
Share on other sites

Ok so i am talking about the second form, the one with the hello variable.  But the problem isn't that I need to keep the $_POST['class'] variable around and bring it to the next form.  The problem, is that whatever I type into the text field hello (from that form) is not passed on to editclasspage.php when the page recieves $_POST['class'], even though they seem to be completely independent.  However if I load the page up stand alone without it receiving the the $_POST['class'] variable then the hello variable DOES send to editclasspage.php as expected.

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.