Djagloi Posted May 1, 2019 Share Posted May 1, 2019 I have this code: Quote $result = mysql_query($sql); echo " <form action='https://test.com/forum/index.php?/search/&q=". $row['record_meta_keywords'] ." &type=cms_records7&search_and_or=and&search_in=titles'> "; echo " <select name='/search/&q=". $row['record_meta_keywords'] ." &type=cms_records7&search_and_or=and&search_in=titles'> "; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['record_meta_keywords'] ."'>" . $row['record_meta_keywords'] ."</option>"; } echo " </select> "; echo " <br><br> "; echo " <input type='submit'> "; echo " </form> "; ?> The problem is that when I choose an option from the dropdown (in this case Majestic Lanes) and click submit, it sends me to this URL: https://test.com/forum/index.php?%2Fsearch%2F%26q%3D+%0D%0A%26type%3Dcms_records7%26search_and_or%3Dand%26search_in%3Dtitles=Majestic+Lanes I need it to send me to this URL: https://test.com/forum/index.php?/search/&q=Majestic%20Lanes%20&type=cms_records7&search_and_or=and&search_in=titles I don't know PHP well enough to fix the code myself. Can anyone assist with this please? Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/ Share on other sites More sharing options...
gw1500se Posted May 1, 2019 Share Posted May 1, 2019 The first thing you need to do is remove the deprecated mysql code and replace it with PDO or at least mysqli. That you can even use mysql implies that your version of PHP is long ago obsolete. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566403 Share on other sites More sharing options...
Djagloi Posted May 1, 2019 Author Share Posted May 1, 2019 20 minutes ago, gw1500se said: The first thing you need to do is remove the deprecated mysql code and replace it with PDO or at least mysqli. That you can even use mysql implies that your version of PHP is long ago obsolete. Ok, but can you assist with the code I have up there? Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566404 Share on other sites More sharing options...
ginerjm Posted May 1, 2019 Share Posted May 1, 2019 Change the action attribute on your form to be the url you want. And stop using mysql db interface. It is way out of date! Strongly suggest switching to PDO - it is pretty easy. Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566405 Share on other sites More sharing options...
Djagloi Posted May 2, 2019 Author Share Posted May 2, 2019 18 hours ago, ginerjm said: Change the action attribute on your form to be the url you want. And stop using mysql db interface. It is way out of date! Strongly suggest switching to PDO - it is pretty easy. I did that. The problem is the special characters. I asked for help with the CODE, not the interface. Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566424 Share on other sites More sharing options...
ginerjm Posted May 2, 2019 Share Posted May 2, 2019 (edited) And what IS the problem? And - your attitude re: our pointing out your soon-to-be-a-problem use of the mysql INTERFACE is un-called for. Stop using that block of functions or you will be cursing yourself the day your host discontinues it. Don't say you weren't warned. Edited May 2, 2019 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566425 Share on other sites More sharing options...
gw1500se Posted May 2, 2019 Share Posted May 2, 2019 I, for one, will not help any user with code that is deprecated and obsolete due to potential liability issues. Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566426 Share on other sites More sharing options...
gizmola Posted May 2, 2019 Share Posted May 2, 2019 You didn't provide the actual code that does the redirect upon form submission, so it's anyone's guess. Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566428 Share on other sites More sharing options...
taquitosensei Posted May 3, 2019 Share Posted May 3, 2019 When you use the $row variable in your form action you're not in the $row loop yet and that wouldn't make sense anyways because you'd be creating your form repeatedly, as many times as there are results in your query. Also selecting an option with the value of the URL you want to be redirected to won't work. The value would just get passed with the other form data. For this to work you would need javascript to get the url from the selected option and redirect you. Quote Link to comment https://forums.phpfreaks.com/topic/308659-problem-with-form-url-in-php-code/#findComment-1566437 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.