Index: wp-admin/setup-config.php
===================================================================
--- wp-admin/setup-config.php	(revision 16800)
+++ wp-admin/setup-config.php	(working copy)
@@ -88,14 +88,14 @@
 <link rel="stylesheet" href="css/install.css" type="text/css" />
 
 </head>
-<body>
+<body onload="setFocus();">
 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
 <?php
 }//end function display_header();
 
 switch($step) {
 	case 0:
-		display_header();
+		display_header();            
 ?>
 
 <p>Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.</p>
@@ -114,34 +114,64 @@
 	break;
 
 	case 1:
-		display_header();
+            display_header();
+            if(is_numeric($_POST['error'])) {
+                switch($_POST['error']) {
+                    case 1 :
+                        $error_msg  =  "Cannot connect to the database server with the provided username and password.";
+                        $focus_ele  =   "uname";
+                    break;
+                    case 2 :
+                        $error_msg  =  "Cannot select the database.";
+                        $focus_ele  =   "dbname";
+                    break;
+                    case 3 :
+                        $error_msg  =  "The table prefix can contain only letters, numbers, and underscores.";
+                        $focus_ele  =   "prefix";
+                    break;
+                }                
+                ?>
+                <script type="text/javascript">
+                    function setFocus() {
+                        document.getElementById('<?php echo $focus_ele; ?>').focus();
+                    }
+                </script>
+                <p style="color:red;"><?php echo $error_msg; ?></p>
+                <?php                
+            }
+            $dbname =   !empty($_POST['dbname']) ? trim($_POST['dbname']) : 'wordpress';
+            $uname  =   !empty($_POST['uname']) ? trim($_POST['uname']) : 'username';
+            // password can be left blank
+            $passwrd=   isset($_POST['pwd']) ? $_POST['pwd'] : 'password';
+            $dbhost =   !empty($_POST['dbhost']) ? trim($_POST['dbhost']) : 'localhost';
+            $prefix =   !empty($_POST['prefix']) ? trim(htmlspecialchars($_POST['prefix']),ENT_QUOTES) : 'wp_';            
 	?>
 <form method="post" action="setup-config.php?step=2">
 	<p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
 	<table class="form-table">
 		<tr>
 			<th scope="row"><label for="dbname">Database Name</label></th>
-			<td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
+			<td><input name="dbname" id="dbname" type="text" size="25" value="<?php echo $dbname; ?>" /></td>
 			<td>The name of the database you want to run WP in. </td>
 		</tr>
 		<tr>
 			<th scope="row"><label for="uname">User Name</label></th>
-			<td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
+			<td><input name="uname" id="uname" type="text" size="25" value="<?php echo $uname; ?>" /></td>
 			<td>Your MySQL username</td>
 		</tr>
 		<tr>
 			<th scope="row"><label for="pwd">Password</label></th>
-			<td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
+			<td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo $passwrd; ?>" /></td>
 			<td>...and MySQL password.</td>
 		</tr>
 		<tr>
 			<th scope="row"><label for="dbhost">Database Host</label></th>
-			<td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
+			<td><input name="dbhost" id="dbhost" type="text" size="25" value="<?php echo $dbhost; ?>" /></td>
 			<td>You should be able to get this info from your web host, if <code>localhost</code> does not work.</td>
 		</tr>
 		<tr>
 			<th scope="row"><label for="prefix">Table Prefix</label></th>
-			<td><input name="prefix" id="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
+			<td><input name="prefix" id="prefix" type="text" id="prefix" value="<?php echo $prefix; ?>" size="25" /></td>
 			<td>If you want to run multiple WordPress installations in a single database, change this.</td>
 		</tr>
 	</table>
@@ -161,8 +191,10 @@
 		$prefix = 'wp_';
 
 	// Validate $prefix: it can only contain letters, numbers and underscores
-	if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
-		wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ );
+	if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {                
+                $prefix =   htmlspecialchars($prefix,ENT_QUOTES);
+                setupconfigstep2error('<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.');                              
+        }
 
 	// Test the db connection.
 	/**#@+
@@ -176,9 +208,8 @@
 
 	// We'll fail here if the values are no good.
 	require_wp_db();
-	if ( ! empty( $wpdb->error ) ) {
-		$back = '<p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button">Try Again</a></p>';
-		wp_die( $wpdb->error->get_error_message() . $back );
+	if ( ! empty( $wpdb->error ) ) {               
+		setupconfigstep2error( $wpdb->error->get_error_message() );
 	}
 
 	// Fetch or generate keys and salts.
@@ -272,6 +303,37 @@
 	endif;
 	break;
 }
+
+function setupconfigstep2error($message) {
+    global $wpdb,$dbname,$uname,$passwrd,$dbhost,$prefix;
+    $formdo =   '';             
+    switch(key($wpdb->error->errors)) {
+        case 'db_connect_fail':
+           $formdo  =   1;
+        break;
+        case 'db_select_fail':
+           $formdo  =   2;
+        break;
+        // table prefix error can't thrown by wpdb
+        default :
+           $formdo  =   3;
+        break;
+    }
+	$back = <<<back
+          <p class="step">
+    <form action="setup-config.php?step=1" method="post">  
+        <input name="error" type="hidden" value="{$formdo}" />
+        <input name="dbname" type="hidden" value="{$dbname}" />		
+        <input name="uname" type="hidden" value="{$uname}" />		
+        <input name="pwd" type="hidden" value="{$passwrd}" />		        
+        <input name="dbhost" type="hidden" value="{$dbhost}" />		
+        <input name="prefix" type="hidden" id="prefix" value="{$prefix}" />    
+        <input type="submit" class="button" value="Try Again" name="try-again">
+    </form>
+          </p>
+back;
+        wp_die($message . $back);
+}
 ?>
 </body>
 </html>
