refreshing page after a function call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cscrum
Forum Newbie
Posts: 2
Joined: Sat Jan 11, 2003 2:05 pm

refreshing page after a function call

Post by cscrum »

I have some text that calls a function when clicked. The function updates a value in an array. A number on the page then needs to be changed to reflect this new value. How do I refresh the page without resetting all the values of the array? Here is a sample of what is happening

Code: Select all

<?
session_start();
if (!isset($_SESSION['uid']) ) {
    $_SESSION['s_box']; 
?>

<?php 
Class Box {
var $addeditems;
function add_Remove($id,$qty) {  
    $this->$addeditems[$id] = $qty; 
     }
}
 

$s_box = new Box(); 
?>

<a HREF= "<?php echo ($PHP_SELF); ?>" onclick="<?php $s_box->add_Remove('state_dc','1'); ?>">ADD</a>

<a HREF= "<?php echo ($PHP_SELF); ?>" onclick="<?php $s_box->add_Remove('state_dc','-1'); ?>">Remove</a>

<?php
	if($addeditems['state_dc'] == 1){
?><td><? echo $addeditems['state_dc']; ?></td>
<?
}
?>
When I click "ADD" or "Remove" nothing happens. Any help would be appreciated.
glo-wurm
Forum Newbie
Posts: 13
Joined: Mon Jan 13, 2003 2:07 pm
Location: Naples, FL

Post by glo-wurm »

I think you are confusing PHP to be a client-side language... PHP is server-side, not client-side. You'll need to read up on javascript first for this :P
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Do a View Source in your browser for the page this code is in. When the Add or Remove links are clicked, the action will be exactly what is in the HTML code in the View Source. Since PHP is a server-side language, no PHP code will be run unless the page is reloaded.

You would need to use Javascript to make a page interactive in the way you describe. There's a good treatment of this topic in one of the sticky-posts in this forum.
Post Reply