117 | | display_header(); |
| 117 | display_header(); |
| 118 | if(is_numeric($_POST['error'])) { |
| 119 | switch($_POST['error']) { |
| 120 | case 1 : |
| 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 2 : |
| 125 | $error_msg = "Cannot select the database."; |
| 126 | $focus_element = "dbname"; |
| 127 | break; |
| 128 | case 3 : |
| 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']) ? htmlspecialchars(trim($_POST['dbname']),ENT_QUOTES) : 'wordpress'; |
| 143 | $uname = !empty($_POST['uname']) ? htmlspecialchars(trim($_POST['uname']),ENT_QUOTES) : 'username'; |
| 144 | // password can be left blank |
| 145 | $passwrd= isset($_POST['pwd']) ? htmlspecialchars($_POST['pwd'],ENT_QUOTES) : 'password'; |
| 146 | $dbhost = !empty($_POST['dbhost']) ? trim(htmlspecialchars(trim($_POST['dbhost']),ENT_QUOTES)) : 'localhost'; |
| 147 | $prefix = !empty($_POST['prefix']) ? trim(htmlspecialchars(trim($_POST['prefix']),ENT_QUOTES)) : '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 = array('message' => '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.','code' => 3); |
| 198 | } |
| 199 | |
| 200 | // if a prefix related error hasn't happened, test the database credentials |
| 201 | if( $setup_error==null ) { |
| 202 | // Test the db connection. |
| 203 | /**#@+ |
| 204 | * @ignore |
| 205 | */ |
| 206 | define('DB_NAME', $dbname); |
| 207 | define('DB_USER', $uname); |
| 208 | define('DB_PASSWORD', $passwrd); |
| 209 | define('DB_HOST', $dbhost); |
| 210 | /**#@-*/ |
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 | | |
| 212 | // We'll fail here if the values are no good. |
| 213 | require_wp_db(); |
| 214 | if ( ! empty( $wpdb->error ) ) { |
| 215 | switch(key($wpdb->error->errors)) { |
| 216 | case 'db_connect_fail': |
| 217 | $setup_error = array('code' => 1); |
| 218 | break; |
| 219 | case 'db_select_fail': |
| 220 | $setup_error = array('code' => 2); |
| 221 | break; |
| 222 | } |
| 223 | $setup_error['message'] = $wpdb->error->get_error_message(); |
| 224 | } |
| 225 | } |
| 226 | // check if any error occured above |
| 227 | if( is_array( $setup_error ) ) { |
| 228 | $try_again = '<p class="step"> |
| 229 | <form action="setup-config.php?step=1" method="post"> |
| 230 | <input name="error" type="hidden" value="' . $setup_error['code'] . '" /> |
| 231 | <input name="dbname" type="hidden" value="' .htmlspecialchars($dbname,ENT_QUOTES). '" /> |
| 232 | <input name="uname" type="hidden" value="' .htmlspecialchars($uname,ENT_QUOTES). '" /> |
| 233 | <input name="pwd" type="hidden" value="' .htmlspecialchars($passwrd,ENT_QUOTES). '" /> |
| 234 | <input name="dbhost" type="hidden" value="' .htmlspecialchars($dbhost,ENT_QUOTES). '" /> |
| 235 | <input name="prefix" type="hidden" id="prefix" value="' .$prefix. '" /> |
| 236 | <input type="submit" class="button" value="Try Again" name="try-again"> |
| 237 | </form> |
| 238 | </p>'; |
| 239 | wp_die($setup_error['message'] . $try_again); |
| 240 | } |