Jump to content

PHP page reload


itachi77

Recommended Posts

Hi all, just signed up and this forum looks like a pretty good source of information. 

I am a beginner to PHP and would like help in relation to reloading of a php page.  I have two text boxes in which a user can specify the name of a product and the quantity they would like.  They have the option to add more products so when they click on the Add Product button the page reloads and the selection they made is added to an associative array which can on submission of the complete form be used in an sql query to retrieve price etc. 

The problem is every time the page reloads the array needs to be redefined so the previous product information is lost.  Is there a way to reload the page but not having to redefine the array?  Only one person is going to be using this application hence not using cookies.  Thanks

 

<?php
$products=array();
if(isset($_POST['product'])){

    $products +=array($_POST['product']=>$_POST['quantity']);

    
}
else
    {
    
}

foreach($products as $ind=>$val)
    echo "$val : $ind" ."<br>"
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method='POST'>

<input type="text" name="product"/>
<input type="text" name="quantity"/>
<input type="submit" value="Add Product"/>

</form>

 

Link to comment
https://forums.phpfreaks.com/topic/204093-php-page-reload/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.