Jump to content

Recommended Posts

Hello, I am learning php in a class for school and I was hoping I could get some help with some code. I am trying to make a game life counter. I just want it to have simple +1, -1 and reset buttons. I have gotten it to add and subtract the first time, but it will not continue adding/subtracting. Thank you for any help you can give. Here is the code I'm having issues with:

 

<?php

session_start();

?>

 

<form method="post" action ="">

<input type="submit" name="name" value="Add"/>

<input type="submit" name="name" value="Minus"/>

<input type="submit" name="name" value="Reset"/>

</form>

 

<?

lifeTotal();

 

function lifeTotal()

{

 

$_SESSION['total']=20;

 

if($_POST["name"] == 'Add')

{

$_SESSION['total']++;

echo $_SESSION['total'];

}

else if($_POST["name"] =='Minus')

{

$_SESSION['total']--;

echo $_SESSION['total'];

}

}

?>

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.