Can't work with value posted from a previous page

I'm having problems with a value that I pass from one page to another. It arrive ok and at the beggining I can get the value, but after clicking on a button on my new page to confirm value is gone.

I set the value first like this:

echo '<a href="removeproduct.php?product_id=' . $_GET ['product_id'] . '">';

And on my new page I see the address correct:

www.mysite.com/removeproduct.php?product_id=11

I use echo to display product_id value and it is ok but after cliking a confirmation button, my URL loses the ?product_id part.

I guess my question is rather silly and simple but I'm completely newbie in HTML and PHP and have lost yet hours with this issue.

My code in the new page (removeproduct.php) is this:

echo 'Value '. $_GET ['product_id'];

if (isset ( $_POST ['confirmar'] )) {

// Lets find the product
// Connect to the database
$dbc = mysqli_connect ( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );

// Grab the product data from the data base

$query = "SELECT user_id FROM product WHERE product_id = '" . $_GET ['product_id'] . "'";
echo 'value 2 '. $_GET ['prod_id'];  **// value here is NULL!!!**
$data = mysqli_query ( $dbc, $query );

if (mysqli_num_rows ( $data ) == 1) {
// The product row was found so display the user data
$row = mysqli_fetch_array ( $data );
// Lets check the product belong to the user
if ($_SESSION ['user_id'] == $row ['user_id']) {
    // If it belongs and user is allowded to erase a product
        $query = "DELETE FROM product WHERE product_id = '" . $_GET ['product_id'] . "'";
        $data = mysqli_query ( $dbc, $query );
        $home_url = 'http://' . $_SERVER ['HTTP_HOST'] . dirname ( $_SERVER ['PHP_SELF'] `) . '/dashboard.php';`
        // Confirm success with the user
        echo "<script>setTimeout(\"location.href ='" . $home_url . "';\",2000);</script>";
        echo '¡Tus datos han sido guardados correctamente!';
} else {
    echo '<p class="error">No tiene autorización para acceder a ese producto. </p>';
}
} // End of check for a single row of user results

else {
echo '<p class="error">Tuvimos un error al acceder al producto. </p>';
}
}else if (isset ( $_POST ['cancelar'] )) {
    $home_url = 'http://' . $_SERVER ['HTTP_HOST'] . dirname ( $_SERVER ['PHP_SELF'] ) . '/dashboard.php';
    // Confirm success with the user
    echo "<script>setTimeout(\"location.href ='" . $home_url . "';\",2000);</script>";
    echo '¡Se han descartado los cambios!';
}

mysqli_close ( $dbc );

?>
<form enctype="multipart/form-data" method="post"
    action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <button name="confirmar" value="confirmar" type="submit">Confirmar</button>
    <button name="cancelar" value="cancelar" type="submit">Cancelar</button>
</form>

Please, I'll appreciate if somebody can help me.

Thanks,

Answers


Instead of making the form action $SERVER['PHP_SELF'], make it $_SERVER['REQUEST_URI']

Like

<form enctype="multipart/form-data" method="post"
action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<button name="confirmar" value="confirmar" type="submit">Confirmar</button>
<button name="cancelar" value="cancelar" type="submit">Cancelar</button>
</form>

Need Your Help

Import into sql database from excel where data is horizontal

sql sql-server excel ms-office

I am working on this database and I have to import this data from an excel sheet. But the problem is the data is Horizontal some what like this!

Can't map roles to groups using ibm-application-bnd.xml

websphere jaas user-roles

I'm trying to map user groups using ibm-application-bnd.xml. Put it into META-INF folder. On try to access secure page get next message:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.