Jump to content

[SOLVED] count help


adv

Recommended Posts

edit :dunno if it`s really a count problem but that`s all my english

 

hello

in a form if u submit the data ... and the user is wrong

i saw on some webpages ..

You have 4 chances .

how do i do it when a user press submit button and the data is incorrect to apear " you have  4 chances .. 3 chances ..  2  .. 1

 

Link to comment
https://forums.phpfreaks.com/topic/82310-solved-count-help/
Share on other sites

I just made this for you to trie so you can understand sessions..

 

 

if you enter the name redarrow you get the congratulations...

 

 

<?php session_start();

if($_POST['submit']){

$username=$_POST['username'];

$name="redarrow";

if($username==$name){

echo "Congratulations you win!";

unset($_SESSION['count']);

echo "<br><br><a href=" .$_SESRVER['PHP_SELF']. ">Please try agin</a>";

exit;

}else{

if (empty($_SESSION['count'])) {
   
$_SESSION['count'] = 1;

} else {

$_SESSION['count']++;


if($_SESSION['count']==4){

echo " sorry you lose!";

unset($_SESSION['count']);

echo "<br><br><a href=" .$_SESRVER['PHP_SELF']. ">Please try agin</a>";

exit;
}
}
  }
   }
?>

<html>

<title>Session Count test</title>

<head>

</head>

<body>

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

<br>

you have tried <?php echo $_SESSION['count']; ?> times!

<br><br>

Please enter your name

<br><br>

<input type="text" name="username">

<br><br>

<input type="submit" name="submit" value="SEND">

</form>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/82310-solved-count-help/#findComment-418371
Share on other sites

redarrow in ur code it doesn`t count .. if u click submit a couple of times it stays to 1 times

 

i tried soemthing like u

 

    <?
session_start();

  if(isset($_POST['submit'])) {
  	if (empty($_SESSION['count'])) {
	$_SESSION['count']=4;
   }else{
   $_SESSION['count']--;
   	}   
   } 
if($_SESSION['count']==0){
echo "blocked";
}
echo $_SESSION['count'];
  
  ?>

but it doesn`t drop from 4 ..

Link to comment
https://forums.phpfreaks.com/topic/82310-solved-count-help/#findComment-418398
Share on other sites

try this

 

 

<?php

session_start();

 

if (!isset($_SESSION['counter']))

{

$_SESSION['counter'] = 4;

}

else

{

$_SESSION['counter']--;

}

 

 

if ($_SESSION['counter'] < 1)

{

echo "<h1>no more tries</h1>";

}

else

{

echo "<h1>you got ".$_SESSION['counter']." left<h1>";

}

echo "<a href='{$_SERVER['PHP_SELF']}'>Test Counter</a>";

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/82310-solved-count-help/#findComment-418407
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.