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