| 117 | | display_header(); |
| | 117 | display_header(); |
| | 118 | if( isset( $_POST['setup_error'] ) ) { |
| | 119 | switch( $_POST['setup_error'] ) { |
| | 120 | case 'db_connect_fail' : |
| | 121 | $error_msg = "Cannot connect to the database server with the provided username,password and host combination."; |
| | 122 | $focus_element = "uname"; |
| | 123 | break; |
| | 124 | case 'db_select_fail' : |
| | 125 | $error_msg = "Cannot select the database."; |
| | 126 | $focus_element = "dbname"; |
| | 127 | break; |
| | 128 | case 'invalid_prefix' : |
| | 129 | $error_msg = "The table prefix can contain only letters, numbers, and underscores."; |
| | 130 | $focus_element = "prefix"; |
| | 131 | break; |
| | 132 | } |
| | 133 | ?> |
| | 134 | <script type="text/javascript"> |
| | 135 | function setFocus() { |
| | 136 | document.getElementById( '<?php echo $focus_element; ?>' ).focus(); |
| | 137 | } |
| | 138 | </script> |
| | 139 | <p style="color:red;"><?php echo $error_msg; ?></p> |
| | 140 | <?php |
| | 141 | } |
| | 142 | $dbname = !empty( $_POST['dbname'] ) ? trim( $_POST['dbname'] ) : 'wordpress'; |
| | 143 | $uname = !empty( $_POST['uname'] ) ? trim( $_POST['uname'] ) : 'username'; |
| | 144 | // password can be left blank |
| | 145 | $passwrd= isset( $_POST['pwd'] ) ? $_POST['pwd'] : 'password'; |
| | 146 | $dbhost = !empty( $_POST['dbhost'] ) ? trim( $_POST['dbhost'] ) : 'localhost'; |
| | 147 | $prefix = !empty( $_POST['prefix'] ) ? trim( $_POST['prefix'] ) : 'wp_'; |
| 164 | | if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) |
| 165 | | wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ ); |
| | 195 | if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) { |
| | 196 | $prefix = htmlspecialchars( $prefix, ENT_QUOTES ); |
| | 197 | $setup_error = new WP_Error( 'invalid_prefix', '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ); |
| | 198 | } |
| | 199 | // if a prefix related error hasn't happened, test the database credentials |
| | 200 | if( $setup_error == null ) { |
| | 201 | // Test the db connection. |
| | 202 | /**#@+ |
| | 203 | * @ignore |
| | 204 | */ |
| | 205 | define('DB_NAME', $dbname); |
| | 206 | define('DB_USER', $uname); |
| | 207 | define('DB_PASSWORD', $passwrd); |
| | 208 | define('DB_HOST', $dbhost); |
| | 209 | /**#@-*/ |
| 167 | | // Test the db connection. |
| 168 | | /**#@+ |
| 169 | | * @ignore |
| 170 | | */ |
| 171 | | define('DB_NAME', $dbname); |
| 172 | | define('DB_USER', $uname); |
| 173 | | define('DB_PASSWORD', $passwrd); |
| 174 | | define('DB_HOST', $dbhost); |
| 175 | | /**#@-*/ |
| 176 | | |
| 177 | | // We'll fail here if the values are no good. |
| 178 | | require_wp_db(); |
| 179 | | if ( ! empty( $wpdb->error ) ) { |
| 180 | | $back = '<p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button">Try Again</a></p>'; |
| 181 | | wp_die( $wpdb->error->get_error_message() . $back ); |
| 182 | | } |
| 183 | | |
| | 211 | // We'll fail here if the values are no good. |
| | 212 | require_wp_db(); |
| | 213 | if ( ! empty( $wpdb->error ) ) { |
| | 214 | $setup_error = $wpdb->error; |
| | 215 | } |
| | 216 | } |
| | 217 | // check if any error occured above |
| | 218 | if( $setup_error->get_error_code() ) { |
| | 219 | $try_again = '<p class="step"> |
| | 220 | <form action="setup-config.php?step=1" method="post"> |
| | 221 | <input name="setup_error" type="hidden" value="' . $setup_error->get_error_code() . '" /> |
| | 222 | <input name="dbname" type="hidden" value="' . htmlspecialchars( $dbname, ENT_QUOTES ) . '" /> |
| | 223 | <input name="uname" type="hidden" value="' . htmlspecialchars( $uname, ENT_QUOTES ) . '" /> |
| | 224 | <input name="pwd" type="hidden" value="' . htmlspecialchars( $passwrd, ENT_QUOTES ) . '" /> |
| | 225 | <input name="dbhost" type="hidden" value="' . htmlspecialchars( $dbhost, ENT_QUOTES ) . '" /> |
| | 226 | <input name="prefix" type="hidden" id="prefix" value="' . $prefix . '" /> |
| | 227 | <input type="submit" class="button" value="Try Again" name="try-again"> |
| | 228 | </form> |
| | 229 | </p>'; |
| | 230 | wp_die( $setup_error->get_error_message() . $try_again ); |
| | 231 | } |