OK, so I asked a friend for a little help. It works beter than it did yesterday, but I can't logout! It's got
Logged in as
Continue
stuck at the top. That text comes from the
if (!(($usr == $usrnme1) && ($pwd ==.....)))
statement in the script below:
<html>
<head>
<title>Shop.php</title>
</head>
<body>
<?php
error_reporting(0);
$usrnme1 = "admin";
$psswrd1 = "admin";
$usrnme2 = "user";
$psswrd2 = "user";
session_start();
session_register("usr", "pwd");
$afile = "shopinfo.inf";
if (!(($usr == $usrnme1) && ($pwd == $psswrd1)) &&
(($usr == $usrnme2) && ($pwd == $psswrd2)))
{
print("<form method=post>
<b>Please Login:</b><br><br>
Username: <input type=text name=usr><br>
Password: <input type=password name=pwd><br><br>
<input type=submit name=submit value=Login>
<input type=hidden name=action value=checklogin>
</form>");
}
else
{
print("<form method=post><b>Logged in as ".$usr."</b><br><br>
<a href=http://devin/custom.php?mode=shop&action=shopstart>Continue</a></form>");
}
if ($action == "checklogin")
{
if (($usr == $usrnme1) && ($pwd == $psswrd1))
{
print("<form method=post>
<a href=http://devin/custom.php?mode=shop&action=add>Add Item</a><br>
<a href=http://devin/custom.php?mode=shop&action=delete>Delete Item</a><br>
<a href=http://devin/custom.php?mode=shop&action=show>Show Items</a><br>
<a href=http://devin/custom.php?mode=shop&action=logout>Logout</a><br>
</form>");
}
elseif (($usr == $usrnme2) && ($pwd == $psswrd2))
{
print("<form method=post>");
print("Click <a href=http://devin/custom.php?mode=shop&action=shopstart>here</a> to shop");
print("</form>");
}
else
{
print("<form method=post>");
print("<b>Incorrect username and/or password</b><br><br>");
print("Please try to <a href=http://devin/custom.php?mode=shop&action=>LOGIN</a> again");
print("</form>");
}
}
if ($action == "add")
{
if (is_file($afile))
{
$f = fopen($afile, "a");
print("<form method=post>");
print("Item : <input type=text name=itemname><br>
Prince : <input type=text name=itemprice><br>
<input type=submit name=submit value=Add Item><br><br>");
if ($itemname){
fputs($f, "$itemname-$itemprice,");
print("Add another item?<br>");
print("<a href=http://devin/custom.php?mode=shop&action=add>Yes</a> ");
print("<a href=http://devin/custom.php?mode=shop&action=shopstart>No</a><br>");
}
print("</form>");
}
else
{
print("<form method=post>");
print("File not found<br><br>");
print("Click <a href=http://devin/custom.php?mode=shop&action=checklogin>here</a> to try again");
$f = fopen($afile, "w");
print("</form>");
}
fclose($f);
}
if ($action == "showitems")
{
print("Items in stock:<br><br>");
$f = file($afile);
foreach ($f as $key=>$val)
{
$entry = explode(",",$val);
foreach ($entry as $key2=>$val2)
{
$tmp=explode("-",$val2);
$item = $tmp[0];
$price = $tmp[1];
if ($item)
{
print("$item R".number_format($price,2)."<br>");
}
}
}
}
if ($action == "shopstart")// && (($usr == $usrnme2) && ($pwd == $psswrd2)))
{
print("<form method=post>");
print("Welcome $usr<br><br>");
print("<a href=http://devin/custom.php?mode=shop&action=selectitems>Shop </a><br>");
print("<a href=http://devin/custom.php?mode=shop&action=logout>Logout</a><br>");
if (($usr == $usrnme1) && ($pwd == $psswrd1))
{
print("<a href=http://devin/custom.php?mode=shop&action=checklogin>Back to start</a><br>");
}
pritn("</form>");
}
if ($action == "selectitems")
{
print("<form method=post>");
print("Select the items you want<br><br>");
$f = file($afile);
foreach ($f as $key=>$val){
$entry = explode(",",$val);
foreach ($entry as $key2=>$val2){
$tmp=explode("-",$val2);
$item = $tmp[0];
$price = $tmp[1];
if ($item){
print("<input type=checkbox name=$item> $item R".number_format($price,2)."<br>"); }
}
}
print("<input type=submit name=submit value=Submit>
<input type=hidden name=action value=checkout>
</form>");
}
if ($action == "checkout")
{
print("You have selected the following<br><br>");
foreach ($f as $itemid)
{
if ($itemname)
{
print("$itemname at a cost of $itemprice<br>");
$total += $itemprice;
}
}
}
if ($action == "logout")
{
$usr = null;
$pwd = null;
print("<form method=post>");
print("You are no longer logged in<br><br>");
print("To login again, click <a href=http://devin/custom.php?mode=shop&action=>HERE</a><br>");
print("</form>");
}
?>
</body>
</html>
What I'm asking, is if you could just please check this out (cut and paste if would make life easier) and tell me what I'm doing wrong.
Thanks...