I'm just beginning to mess with functions, and I'm redesigning my login/admin script for my website with them, instead of without ( so its cleaner, smaller, easier to tweak, etc etc etc. And I'm having a few problems, First off, the $PHP_SELF variable doesnt seem to return inside a function, and two variables i post ( through a function ) don't seem to actually get posted...Code follows, any help appreciated.
<?php
function login () {
echo "<center>Welcome to the Infrequency.net Admin page.";
echo "<br>";
echo "Please login.";
echo "<p>";
echo "<form action=$PHP_SELF method=post>";
echo "Username: <input type=username name=un>";
echo "<br>";
echo "Password:<input type=password name=pw>";
echo "<br>";
echo "<input type=submit value=Login>";
echo "</form>";
echo "</center>";
}
function checkpass () {
$db = mysql_connect("xxx", "xxx");
mysql_select_db("xxx",$db);
$resulta = mysql_query("SELECT * FROM login WHERE name=$un",$db);
$myrow = mysql_fetch_array($resulta);
$name = $myrow["name"];
$pass = $myrow["password"];
if ( $pw != $pass ) {
echo "Password Incorrect";
login();
}
if ( $pw == $pass ) {
echo "<meta http-equiv=\"refresh\" content=\"2; URL=linktoscripthere\">";
}
}
if ($un == "") {
if ($pw == "") {
login();
}
}
else {
checkpass();
}
?>