Variable always resetting

前端 未结 2 1434
小鲜肉
小鲜肉 2021-01-26 06:00

I\'m creating a game like mastermind using forms. My problem is that I have a variable $attempts, and I want it to increase every time the user guesses a number, but it seems to

2条回答
  •  攒了一身酷
    2021-01-26 06:30

    Are you submitting the form on every guess? If so you need to set a session variable like:

    $_SESSION['attempts'] += 1;
    

    Just to clarify something that it seems you are missing. A php script is code that runs on the server producing a document (frequently html) to be sent to a client. Therefore it isn't very interactive accross requests. If you want code to be ran on the client side you need to use Javascript. Javascript has the benefit of not needed to pass information accross the internet between client and server.

提交回复
热议问题