php - Counting inside an if/else statement -
php - Counting inside an if/else statement -
i have log in page, users asked come in code. want count how many times users enters wrong code, , if more 3 times, show page telling them restart processes, counter outputs 1, though type wrong code multiple times.
<div class="container"> <div class="alert alert-success" role="alert" align="center"> <p>a code has been sent email</p> <p>please consult email proceed login</p> </div> <form class="form-signin" method="post"> <h2 class="form-signin-heading">enter code</h2> <input type="hidden" name="partneremail" value="<?php echo $_post['partneremail']; ?>"> <input class="form-control" type="text" name="partnercode" placeholder="code"> <button class="btn btn-lg btn-primary btn-block" type="submit">accept</button> </form> </div> <!-- /container --> <?phpsession_start();echo $_session['partneremail'];?> <div class="container"> <?php include_once "conn.php"; $partnercode = $_post['partnercode']; $partneremail = $_session['partneremail']; $sql = "select * partners partner_email='$partneremail' , partner_login_code='$partnercode' , partner_active ='yes'"; $counter = 0; echo $counter; $result = $conn->query($sql); if (mysqli_num_rows($result)>0){ echo '<div class="alert alert-success" role="alert" align="center"> <p>congratz - logged in successfully!</p> </div>'; } else { echo '<div class="alert alert-danger" role="alert" align="center"> <p>error - please consult email right code!</p> </div>'; $counter ++; echo $counter; ?> <script> $(".alert").effect("shake");</script> <?php } echo $counter; ?>
you need store $counter value.
first line says:
$counter = 0; echo $counter;
it can transformed to:
if(isset($_session['counter']) && $_session['counter'] > 0){ $counter = $_session['counter']; }else{ $counter = 0; }
the part says
$counter ++;
become
$counter ++; $_session['counter'] = $counter;
and can access on other pages (as long them php , can access sessions variables).
php jquery mysql database counter
Comments
Post a Comment