I'm making a user login page that when logged in, goes to an FTP file upload page. Everything works fine until you click the upload button. The value of the variable "$user" passes to the upload page, but doesn't when it tries to connect to the ftp server. Here's my code:
<?PHP
$user = $_POST['user_name'];
$pw = $_POST['password'];
$submit = $_POST['submit'];
$error = " ";
$login_box = "";
$upload_box = "";
?>
<html>
<head>
<title>White Fire Designs - User Pages</title>
<style type="text/css">
<!--
.error
{
color: #ff0000;
font-weight: bold;
}
.link
{
color: #0080ff;
text-decoration: none;
}
.link:hover
{
color: #ff0000;
text-decoration: underline;
}
//-->
</style>
</head>
<body>
<table width="100%" height="100%" border="0">
<tr>
<td align="center" valign="middle">
<table width="500" height="250" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #000000;">
<tr>
<td>
<table width="500" height="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="150" height="180" valign="top"><img src="images/new_flame_logo-(150x180).gif" width="150" height="180"></td>
<td rowspan="2" width="350" height="230" align="center" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;">
<?PHP
if ($submit == "Login")
{
if ($user == "")
{
$error = "Please enter your user name.";
echo
"
<form name='login' action='$PHP_SELF' method='post'>
<table width='325' border='0' cellpadding='0' cellspacing='0' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'>
<tr>
<td colspan='2' height='70'> </td>
</tr>
<tr>
<td width='75'><b>User</b></td>
<td width='250' style='font-family: Verdana, Arial, Helvetica, sans-serif;'><input type='text' name='user_name' value='' style='width: 100px; height: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'>@whitefiredesigns.com</td>
</tr>
<tr>
<td width='75'><b>Password</b></td>
<td width='250' style='font-family: Verdana, Arial, Helvetica, sans-serif;'><input type='password' name='password' value='' style='width: 100px; height: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'></td>
</tr>
<tr>
<td colspan='2' height='50' align='center' valign='middle'>
<input type='submit' name='submit' value='Login'>
</td>
</tr>
<tr>
<td colspan='2' height='20' align='center' class='error'>" . $error . "</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height='50' align='center' valign='middle' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;'>
<b>USER LOGIN</b>
</td>
</tr>
";
}
else if (($pw == "") && ($user != ""))
{
$error = "Please enter your password.";
echo
"
<form name='login' action='$PHP_SELF' method='post'>
<table width='325' border='0' cellpadding='0' cellspacing='0' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'>
<tr>
<td colspan='2' height='70'> </td>
</tr>
<tr>
<td width='75'><b>User</b></td>
<td width='250' style='font-family: Verdana, Arial, Helvetica, sans-serif;'><input type='text' name='user_name' value='" . $user . "' style='width: 100px; height: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'>@whitefiredesigns.com</td>
</tr>
<tr>
<td width='75'><b>Password</b></td>
<td width='250' style='font-family: Verdana, Arial, Helvetica, sans-serif;'><input type='password' name='password' value='' style='width: 100px; height: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'></td>
</tr>
<tr>
<td colspan='2' height='50' align='center' valign='middle'>
<input type='submit' name='submit' value='Login'>
</td>
</tr>
<tr>
<td colspan='2' height='20' align='center' class='error'>" . $error . "</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height='50' align='center' valign='middle' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;'>
<b>USER LOGIN</b>
</td>
</tr>
";
}
else
{
echo $upload_box;
}
}
else if ($submit == "Upload File(s)")
{
$connection = ftp_connect("whitefiredesigns.com");
$login_stat = ftp_login($connection, $user . "@whitefiredesigns.com", $pw);
if ((!$connection) || (!$login_stat))
{
$error = "Failed to connect to server.";
echo
"
<form name='upload' action='$PHP_SELF' method='POST' enctype='multipart/form-data'>
<table width='350' height='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2' align='center' valign='middle' class='error'>" . $error . "</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height='50' align='center' valign='middle' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;'>
<b>FTP FILE UPLOAD</b>
</td>
</tr>
";
}
else
{
$destination_file = $_FILES['file1']['name'];
$source_file = $_FILES['file1']['tmp_name'];
$upload = ftp_put($connection, $destination_file, $source_file, FTP_BINARY);
if (!$upload)
{
$error = "FTP File Upload Failed.";
echo
"
<form name='upload' action='$PHP_SELF' method='POST' enctype='multipart/form-data'>
<table width='350' height='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='20' align='right' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; padding-right: 5px;'>Welcome " . ucfirst($user) . "</td>
</tr>
<tr>
<td colspan='2' align='center' class='error'>" . $error . "</td>
</tr>
<tr>
<td height='50' align='center' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'><a href='javascript: history.back();' class='link'>back</a></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height='50' align='center' valign='middle' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;'>
<b>FTP FILE UPLOAD</b>
</td>
</tr>
";
}
else
{
echo
"
<form name='upload' action='$PHP_SELF' method='POST' enctype='multipart/form-data'>
<table width='350' height='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='20' align='right' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; padding-right: 5px;'>Welcome " . ucfirst($user) . "</td>
</tr>
<tr>
<td align='center' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'>
<b>Uploaded <span style='color: #ff0000;'>$destination_file</span> to:</b><br>
http://www.whitefiredesigns.com/$user
<p> </p>
<b>File URL:</b><br>
<a href='http://www.whitefiredesigns.com/$user/$destination_file' class='link'>http://www.whitefiredesigns.com/$user/$destination_file</a>
</td>
</tr>
<tr>
<td colspan='2' height='20' align='center' class='error'>" . $error . "</td>
</tr>
<tr>
<td height='50' align='center' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;'><a href='javascript: history.back();' class='link'>back</a></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height='50' align='center' valign='middle' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;'>
<b>FTP FILE UPLOAD</b>
</td>
</tr>
";
}
}
}
else
{
echo $login_box;
}
?>
<tr>
<td colspan="2" height="20">
<table width="500" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="250" style="background-color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #ffffff;"> ©2005 White Fire Designs.</td>
<td width="250" align="right" style="background-color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #ffffff;">http://www.whitefiredesigns.com </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>