rizzler Posted July 5, 2021 Share Posted July 5, 2021 I have this loop on a shorturl website i own that selects domains from my website and lists them in a dropdown list where users can select one domain to use as url shortener. The problem is that when a users selects and entry from the dropdown list this created only the [[[main_url]]] entry from the database table bellow can be used. When someone selectes "coolartistname.site.com the submit button cannot be pressed. in other words it's not adding the SELECTED attribute other than the [[[main_url]]] domain. Can anyone see on the code bellow why this would happen? When i echo $shortUrlDomains it's just saying "Array" and $_REQUEST['shortUrlDomain'] shows nothing. **Index.php** // get base urls $shortUrlDomains = getShortUrlDomains(); <?php foreach ($shortUrlDomains AS $k => $shortUrlDomain) { // active domains only if (($shortUrlDomain['premium_only'] !== '1') && ($shortUrlDomain['premium_only'] !== $Auth->id)) { continue; } echo '<option value="' . (int)$k . '"'; if (isset($_REQUEST['shortUrlDomain'])) { if ($k == (int)$_REQUEST['shortUrlDomain']) { echo 'SELECTED'; } } echo '>'; echo $shortUrlDomain['domain']; if ($disabled == true) { echo ' (' . safeOutputToScreen(t('unavailable', 'unavailable')) . ')'; } '</option>'; } echo '</optgroup>'; ?> FUNCTIONS.PHP function getShortUrlDomains() { // if we already have it cached if(defined('_SETTINGS_SHORT_URL_DOMAINS')) { return unserialize(_SETTINGS_SHORT_URL_DOMAINS); } // get connection $db = Database::getDatabase(true); // load from database $domains = $db->getRows("SELECT id, domain, premium_only, status FROM url_domain ORDER BY premium_only ASC, id ASC"); // organise and replace site url $rs = array(); foreach($domains AS $domain) { if($domain['domain'] == '[[[main_url]]]') { $domain['domain'] = _CONFIG_SITE_FULL_URL; } $rs[$domain{'id'}] = $domain; } **MYSQL DATABASE** url_domain (id, domain, premium_only, status, date_created, owner) VALUES (1, '[[[main_url]]]', 0, 'enabled', '2019-03-02 08:13:00', 1) (14, 'coolartistname.site.com', 6, 'enabled', '2020-04-18 19:21:59', 6); Quote Link to comment https://forums.phpfreaks.com/topic/313048-selected-entry-will-not-get-selected/ Share on other sites More sharing options...
gw1500se Posted July 6, 2021 Share Posted July 6, 2021 Don't use $_REQUEST. It has been deprecated. Use $_POST or $_GET depending on your form, which you did not post. Be sure to turn on error reporting. You don't do any error checking of your database query either. Quote Link to comment https://forums.phpfreaks.com/topic/313048-selected-entry-will-not-get-selected/#findComment-1587858 Share on other sites More sharing options...
requinix Posted July 6, 2021 Share Posted July 6, 2021 $_REQUEST is discouraged, not deprecated, due to the way that it may or may not contain certain values depending on php.ini settings. Best practice is to get the value specifically from the query string ($_GET) or submitted form data ($_POST). But unless you have a weird setup, $_REQUEST should contain both of $_GET and $_POST (if not more). If there is no "shortUrlDomain" key in it then that probably means there was no value being passed, so the first step should be looking at where the value is supposedly being passed to the PHP script. Quote Link to comment https://forums.phpfreaks.com/topic/313048-selected-entry-will-not-get-selected/#findComment-1587861 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.