To all whom may read this:
Server: Currently PWS, soon to be placed on a IIS 3 or 4 server.
PHP: Verison 4.0.4 Win32 Binary with ISAPI
Problem: How do I get the form associated with $Step=="add" to stop showing up when the page loads. I only need the "find" form to show after the user has logged in.
Also, while you are at it... What is the best way to code the script to ask if the level is <1 and then use it with each of the steps?
Take a look all, and tell me how to work this error or errors. Thanks.
<?php
// Includes the path of the database and username and password
include ("c:\wwwroot\jhs\inc\db.inc");
$level=10;
// Sending the user to the login page if login has not been filled out
if($Step=="login"){
$Step="";
}else{
$Step=="login";
}
// SQL functions to edit a user
if($Step=="edit"){
$sql = "UPDATE access SET std_id='$std_id',level='$level' WHERE id=$id";
$result = mysql_query($sql);
echo "$username's Record Updated!";
}
// SQL functions to delete a user
if($Step=="delete"){
$sql = "DELETE FROM access WHERE id=$id";
$result = mysql_query($sql);
echo "$std_id Record deleted!<p>";
}
// SQL functions to add a user
if($Step=="add"){
$sql = "INSERT INTO access (std_id,level) VALUES ('$std_id','$level')";
$result = mysql_query($sql);
echo "$std_id was added!";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<body>
<?
if($Step="add"){
?>
<form>
<input type="hidden" name="login" value="<? echo $login ?>">
Student ID:<input type="text" name="std_id">
<br>
Level:<input type="level" name="level">
<br>
<input type="hidden" name="Step" value="add">
<input type="submit" value="Add User">
<input type="reset" value="Reset">
</form>
<?
}
?>
<?
if($login=="" && $id==$id && $Step=="find"){
// Display user information
$sql = "SELECT * FROM access WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
echo $myrow["id"], $myrow["std_id"];
?>
<!-- Form to edit a user -->
<form>
Student ID:<input type="text" name="std_id" value="<? echo $myrow["std_id"] ?>"><BR>
Level:<input type="level" name="level" value="<?echo $myrow["level"] ?>"><BR>
<input type="hidden" name="id" value="<? echo $myrow["id"] ?>">
<input type="hidden" name="login" value="<? echo $login?>">
<input type="hidden" name="Step" value="edit">
<input type="submit" value="edit">
</form>
<!-- Form to delete a user -->
<form>
<input type="hidden" name="Step" value="delete">
<input type="hidden" name="id" value="<?echo $myrow["id"] ?>">
<input type="hidden" name="login" value="<? echo $login ?>">
<input type="submit" value="delete">
</form>
<?
}
?>
<?
if($Step=="login"){
?>
<form>
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="hidden" name="Step" value="Login">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<?
}
?>
<form>
<input type="hidden" name="login" value="<? echo $login?>">
<select name="id">
<?php
$result = mysql_query("SELECT * FROM access",$db);
while($myrow = mysql_fetch_array($result)) {
?>
<option value="<?echo $myrow["id"] ?>"><? echo $myrow["std_id"] ?></option>
<?
}
?>
</select>
<input type="hidden" name="Step" value="find">
<input type="submit" value="Find">
</form>
</body>