I am using $HTTP_POST_VAR to pass some variables from a form in order that I can then update a record.

Nothing is happening so I included echo statements to see what was being passed and out of 7 statements, only 1 is working.

the first part of the page calls a record in and displays it in the form, so I now that the information is available, but I cannot get it to update as there are no values when I go to update.

Second part of code:

<?php
  if ($HTTP_POST_VARS['Save']) 
  {
    	include("myconnect.php");
$article_id=$HTTP_POST_VARS['article_id'];
$article_top_id=$HTTP_POST_VARS['article_top_id'];
$article_title=$HTTP_POST_VARS['article_title'];
$article_text=$HTTP_POST_VARS['article_text'];
$article_date=$HTTP_POST_VARS['article_date'];
$article_imagelink=$HTTP_POST_VARS['article_imagelink'];
$status=$HTTP_POST_VARS['status'];



$query =("UPDATE article SET article_id='$article_id', article_top_id='$article_top_id',article_title='$article_title', article_text='$article_text',article_date='$article_date',article_imagelink='$article_imagelink',status='$status' WHERE article_id='$article_id'"); 

$result=mysql_query($query);

if ($result) {
header ('Location: next.php?confirm= Item successfully updated');
}//end if result

else {
echo "<b>ERROR: unable to post - Try again</b>";
}//end else

}//end first if


echo "<p><p>You entered the following information:<br>";
echo "<b>article_id:</b> $article_id<br>";
echo "<b>article_top_id:</b> $article_top_id<br>";
echo "<b>article_title:</b> $article_title<br>";
echo "<b>article_text:</b> $article_text<br>";
echo "<b>article_date:</b> $article_date<br>";
echo "<b>article_imagelink:</b> $article_imagelink<br>";
echo "<b>status:</b> $status<br>";
?>

Any help would be apreciated

    Have you tried $POST instead of $HTTP_POST_VARS?

    if ($_POST['Save']) 
      {
        	include("myconnect.php");
    $article_id=$_POST['article_id'];
    $article_top_id=$_POST['article_top_id'];
    $article_title=$_POST['article_title'];
    $article_text=$_POST['article_text'];
    $article_date=$_POST['article_date'];
    $article_imagelink=$_POST['article_imagelink'];
    $status=$_POST['status'];

    depending on what version PHP you are using it does make a difference as well as the php.ini configuration.

      Yes, I have tried that. The first variable is there, but I think that is from the previous page. So nothing is being handled by the code above, even if I use $_POST.

      Thanks for your input though

        Source PHP😛redefined variables

        HTTP POST variables: $_POST
        Opomba: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.

        An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

        This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.

        $HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

        If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

        Is it possible that there is something wrong with your HTML form itself, perhaps if you showed the actual form and how it were coded it might shed some light on why you are having this problem. If you are only passing one variable then it could be typo(s) or possibly something like that but not seeing how the form was written it would be hard to tell.

          Here is the complete code for the page excluding the html, body, head tags.

          <?php
          $article_id = $_GET['article_id'];
          include("myconnect.php");
          $result = mysql_query("SELECT * FROM article WHERE article_id='$article_id'");
          
          ?>
          <h3>Edit Current/Archived Articles</h3>
          <?php
          while ($myrow = mysql_fetch_array($result)) 
          {
          mysql_close();
          ?>
          
          <form name="edit" method="POST" action="next.php">
          
          <input type="hidden"  name="article_id" value= "<?php echo $myrow["article_id"]; ?>" >
          
          <input type="hidden"  name="article_top_id" value= "<?php echo $myrow["article_top_id"]; ?>" >
          <p><b>Title</b><br> 
          
          <input type="text" name="article_title" size="60" maxlength="60" value="<?php echo $myrow["article_title"]; ?>">
          
          <br><b>Article Text</b> <br>
          <textarea name="article_text" cols="45" rows="12" wrap="on"><?php echo $myrow["article_text"]; ?></textarea>
          
          <input type="hidden" name="article_date" size="12" maxlength="12">
          
          
          <br><b>Associated Image</b> <br>
          <input type="text" name="article_imagelink" size="60" maxlength="60" value="<?php echo $myrow["article_imagelink"]; ?>">
          
          <p><b>Current Status</b><br> 
          Current <input type="radio" name="status" value="C" <?php if ($myrow["status"]=="C") { echo "checked"; } ?>>
          Archived <input type="radio" name="status" value="A" <?php if ($myrow["status"]=="A") { echo "checked"; }?>>
          
          <?php
          }// end while
          ?>
          
          <input type="submit" value="Save" name="submit"  ><br>
          
          </form>
          <?php
            if ($_POST['Save']) 
            {
              	include("myconnect.php");
          $article_id=$_POST['article_id'];
          $article_top_id=$_POST['article_top_id'];
          $article_title=$_POST['article_title'];
          $article_text=$_POST['article_text'];
          $article_date=$_POST['article_date'];
          $article_imagelink=$_POST['article_imagelink'];
          $status=$_POST['status'];
          
          
          
          $query =("UPDATE article SET article_id='$article_id', article_top_id='$article_top_id',article_title='$article_title', article_text='$article_text',article_date='$article_date',article_imagelink='$article_imagelink',status='$status' WHERE article_id='$article_id'"); 
          
          $result=mysql_query($query);
          
          if ($result) {
          header ('Location: next.php?confirm= Item successfully updated');
          }//end if result
          
          else {
          echo "<b>ERROR: unable to post - Try again</b>";
          }//end else
          
          }//end first if
          
          echo "<p><p>You entered the <strong>following</strong> information:<br>";
          echo "<b>article_id:</b> $article_id<br>";
          echo "<b>article_top_id:</b> $article_top_id<br>";
          echo "<b>article_title:</b> $article_title<br>";
          echo "<b>article_text:</b> $article_text<br>";
          echo "<b>article_date:</b> $article_date<br>";
          echo "<b>article_imagelink:</b> $article_imagelink<br>";
          echo "<b>status:</b> $status<br>";
          
          ?>
          
          
          </div>
          
          		</div>
          		<div id="rightcol" > <?php require_once('rightnav.htm'); ?>
           </div>
          		</div> 
          			<div id="leftcol" > <?php require_once('leftnav.htm'); ?>
          </div>
          </div>
          	<div id="footer" > Copyright: &copy; Harlequeen 2006 
          	</div>
          	</div>
          	

          I hope someone can see what I'm doing wrong as I can't spot it. I suspect I've been looking at it too long now, but can't stop myself going back and looking again, even though I can't see it.

          Cheers

          Harlequeen

            I noticed the placing of the close statement when I was posting the listing and changed it so it closes the connection after the beginning of the while statement.

            harlequeen

              Remove mysql_close() entirely.

              What exactly is the problem?

                Ok, I will remove that. The problem is that I am calling information into a form from a db, this comes in OK and I can see the information. The next step is to amend the information and update the db. This doesn't happen though. I have tried both $_POST and $HTTP_POST_VAR to pass the variable values from the form so that I can update them in my table. When I click the 'Save' button, that action should pass the values to the variables.

                I simply can't get any values into the variables.

                I was closing the connection but re-opening it later in the code, for the update. I have tried it with removing both and it still doesn't work.

                  I hate to say this, but your script is poorly structured. At the moment the main problems are that you print the form tag on each iteration, and that you check for $POST['Save'] when you should check for $POST['submit']

                  <?php
                  if (isset($_GET['article_id']) && ctype_digit($_GET['article_id'])) {
                  	include 'myconnect.php';
                  	if (isset($_POST['submit'])) {
                  		// process form
                  		// update database
                  	}
                  	// retrieve from database
                  	// print form
                  } else {
                  	die("Article ID not specified or invalid!");
                  }
                  ?>

                    Thanks for your help. I realise that my code is probably all over the place, as i am trying to teach myself how to do this and am adding bits and pieces as I go along.

                    I thought I had changed the button name, but obviously hadn't. Thanks again for your patience.

                    Cheers

                    Harlequeen :o

                      Write a Reply...