Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 28th, 2004, 05:09 PM
Registered User
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Administrative Log-on</title>


$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'>

} 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>";

Please paste text into the area below.<br>

<textarea name="textarea" cols="50" rows="10"></textarea><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());




Old March 28th, 2004, 05:46 PM
richard.york's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

I didn't look too deeply at your code, but here is a thread that addresses a similar problem.

I have posted an example there of uploading a file to a MySQL DB and then viewing it.

If you're still having problems, let us know.

: )

The Spicy Peanut Project

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Login Page errors - Please Solve and Help zirconiumks Beginning PHP 2 October 5th, 2008 07:14 PM
Creating a login page in PHP bhavna General .NET 0 February 16th, 2007 07:32 AM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM
PHP file upload qazi_nomi PHP How-To 2 July 11th, 2004 10:43 PM
php file upload reason1000 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 June 7th, 2003 10:49 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.