Hi, I was trying out the exercise "Using the While function" and everything work fine except when I check the sort checkbox the list is not sorted alphabetically. Maybe because its numbered? Am I doing anything wrong.
Here's the PHP code I typed for the two files involved
moviesite.php
Code:
<?php
session_start();
//check to see if user has logged in with a valid password
if ($_SESSION['authuser'] != 1) {
echo "Sorry, but you don't have permission to view this page, you loser!";
exit();
}
?>
<html>
<head>
<title>My Movie Site - <?php echo $_REQUEST['favmovie']; ?></title>
</head>
<body>
<?php include "header.php"; ?>
<?php
$favmovies = array ("Life Of Brian",
"Stripes",
"Office Space",
"The Holy Grail",
"Matrix",
"Terminator 2",
"Star Wars",
"Close Encounters of the Third Kind",
"Sixteen Canldes",
"Caddyshack");
if (isset($_REQUEST['favmovie'])) {
echo "Welcome to our site, ";
echo $_SESSION['username'];
echo "! <br>";
echo "My favorite movie is ";
echo $_REQUEST['favmovie'];
echo"<br>";
$movierate = 5;
echo "My movie rating for this movie is: ";
echo $movierate;
} else {
echo "My top ". $_POST["num"] . " movies are:<br>";
if (isset($_REQUEST['sorted'])) {
sort($favmovies);
}
//list the movies
$numlist = 1;
while ($numlist <= $_POST["num"]) {
echo $numlist;
echo ". ";
echo pos($favmovies);
next($favmovies);
echo "<br>\n";
$numlist = $numlist + 1;
}
}
?>
</body>
</html>
movie1.php
Code:
<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;
//Check username and password information
if(($_SESSION['username'] == 'Joe') and
($_SESSION['userpass'] == '12345')) {
$_SESSION['authuser'] = 1;
} else {
echo "Sorry, but you don't have permission to view this page, you loser!";
exit ();
}
?>
<html>
<head>
<title>Find My Favorite Movie!</title>
</head>
<body>
<?php
$myfavmovie = urlencode("Life Of Brian");
echo "<a href='moviesite.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favorite movie!";
echo "</a>";
echo "<br>";
echo "Or choose how many movies you would like to see:";
echo "</a>";
echo "<br>";
?>
<form method="post" action="moviesite.php">
<p>Enter number of movies (up to 10):
<input type="text" name="num">
<br>
Check here if you want the list sorted alphabetically:
<input type="checkbox" name"sorted">
</p>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Alexander Lenner