Question

This is my first post, so excuse me if I will not provide the information correctly.

So my problem is the following:

This is the first form:

<h1>Modificare carti</h1>
<br />
<form action="UTLcrt.php" method="post">
Cod Carte: <br /><input type="numeric" name="cod"><br>
Nume: <br /><input type="text" name="nume"><br>
Autor: <br /><input type="text" name="autor"><br>
Editura: <br /><input type="text" name="editura"><br>
Disponibilitate: <br /><input type="text" name="disp"><br>
Pret: <br /><input type="numeric" name="pret"><br>
<select name="vmod">
<option value="mod">Modificare carte</option>
<option value="str">Sterge carte</option>
<option value="src" >Cauta carte</option>
</select>
<input type="submit">
</form>

The UTLcrt.php contains the following code:

<?php
if (isset($_POST['vmod'])) {
    $urls = array(
        'mod' => 'modcrt.php',
        'str' => 'strcrt.php',
        'src' => 'srccrt.php'

    );
    $url = $urls[$_POST['vmod']];
    header("Location: " . $url);
}
?>

And each php page does the following: modcrt.php changes the entry in our database with the same"cod" with the info provided in the first form strcrt.php deletes the register in our database, if the "cod" we entered in the first form finds a match srccrt.php searches in the database if the register with the "cod" provided in the first form was found and shows a possitive message.

My problem is the following: the information I put in the first form doesn't get in the modcrt.php,strcrt.php,src.php pages... the $_Post's are empty...

How to send the information from the first page, trough the second and then to the third?

Was it helpful?

Solution 2

The POST values are empty because the third page isn't receiving a POST request. The order of events is this:

  • User requests the first page.
  • User POSTs a form to the second page, with values.
  • Second page tells the user to issue a GET request to the third page.
  • User requests the third page.

There are a few different ways to keep the information in the chain. You can:

  • Add it to the query string for the redirect
  • Store it in session
  • Store it in a database
  • etc.

The first one might look like this:

header("Location: " . $url . "?key=value");

Where the key/value pair is similar to those in a POST. In this case the values would be available to the third page in GET:

$_GET['key']

If you use session, the values stay server-side. So in the second page you can set the value:

$_SESSION['key'] = $value;

And then retrieve it in the third page:

$value = $_SESSION['key'];

Note that these session values will continue to live on the server until the session times out. You may want to unset them from the session once you're done with them if it starts to add confusion to other pages the user visits which also make use of these values.

OTHER TIPS

You can keep them in Session, by using

$_SESSION['info1']=$info1;

Page 1

 <?php 
 // this starts the session 
 session_start(); 

 // this sets variables in the session 
 $_SESSION['color']='red'; 
 $_SESSION['size']='small'; 
 $_SESSION['shape']='round'; 
 ?> 

Page 2

<?php
$color = $_SESSION['color'];
$size = $_SESSION['size'];
$shape = $_SESSION['shape'];
?> 

and so on...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top