Jump to content
Djagloi

Problem with Form URL in PHP Code

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (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 by ginerjm

Share this post


Link to post
Share on other sites

I, for one, will not help any user with code that is deprecated and obsolete due to potential liability issues.

Share this post


Link to post
Share on other sites

You didn't provide the actual code that does the redirect upon form submission, so it's anyone's guess.

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.