javascript - PHP UPDATE with if and else statement -
i need little script, making library sign in/out , page , have working posts form when sign in , out, want make if trying sign out , never signed in pop-up js alert tell them , can't quite it.
here's code:
<?php session_start(); include_once("connect.php"); date_default_timezone_set("america/winnipeg"); $date = ("m-d-y"); $timeout = date("g:i:s a"); //search existing entries if ("select exists(select * signin_out lname='".$_post['lastname']."' , fname='".$_post['firstname']."' , date='".$date."')") { //if exist run mysql_query("update signin_out set timeout='" . $timeout . "' lname='" . $_post['lastname'] . "' , fname='" . $_post['firstname'] . "' , timeout='' "); header("location: ../index.html"); //if don't exist run } else { header("location: ../index.html"); echo "<script type='text/javascipt'>\n"; echo "alert('you did not sign in!');\n"; echo "</script>"; } ?>
the http location
header sends them ../index.html
long before javascript gets echo
ed out. need have logout.php
page javascript or $_get
variable page redirect them to, , trigger alert box there.
for instance:
... } else { header('location: ../index.php?notloggedin'); }
and somewhere in index.php
:
<?php if(isset($_get['notloggedin'])) { echo '<script>alert("you did not sign in!");</script>'; } ?>
although find alert
box rather intrusive, i'd rather do:
<?php if(isset($_get['notloggedin'])) { echo '<p><strong>you did not sign in!</strong></p>'; } ?>
Comments
Post a Comment