PHP login/upload page
Hey everyone..
I'm having trouble figuring out how to create a "upload" button that will browse for a text file that will be uploaded to a MySQL DB.
The following is what I have for code so far, if anyone can help me with the upload section it would sooo appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Administrative Log-on</title>
</head>
<body>
<?
$db=mysql_connect('host', 'db', 'password') or die("Couldn't connect to the database.");
mysql_select_db('db') or die("Couldn't select the database");
// Add slashes to the username, and make a md5 checksum of the password.
$_POST['user'] = addslashes($_POST['user']);
$_POST['pass'] = md5($_POST['pass']);
$result = mysql_query("SELECT userId FROM users WHERE userName='$_POST[user]' AND userPass='$_POST[pass]'") or die("Couldn't query the user-database.");
$num = mysql_numrows($result);
if (!$num) {
// When the query didn't return anything,
// display the login form.
echo "<h3>title<br><br>
Administration Section</h3>
<form action='$_SERVER[PHP_SELF]' method='post'>
Username: <input type='text' name='user'><br>
Password: <input type='password' name='pass'><br><br>
<input type='submit' value='Login'>
</form>";
} else {
// Start the login session
// We've already added slashes and MD5'd the password
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
// All output text below this line will be displayed
// to the users that are authenticated. Since no text
// has been output yet, you could also use redirect
// the user to the next page using the header() function.
echo "<h3>You have successfully logged in.</h3>";
?>
<p>
Please paste text into the area below.<br>
<br>
<textarea name="textarea" cols="50" rows="10"></textarea><br>
<br>
<input type='submit' value='Submit'>
<?
if (isset($_POST["submit"]))
{
$link = mysql_connect('host', 'db', 'password') or die(mysql_error());
mysql_select_db('db') or die(mysql_error());
/* Validate your input here and if everything is OK, then ... */
$sql = "INSERT INTO daily_text (text) values ('"($_POST["textarea"])."')";
mysql_query($sql) or die(mysql_error());
mssql_close('db');
}
}
?>
</p>
<p> </p>
<p> </p>
</body>
</html>
|