Link to home
Create AccountLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php redirect

I have the following redirect url:

php redirect:
$redirect = "frm_artgallery.php?artist_added=".urlencode($_POST[art_Nme]);

I need to add the following to it:
image_added=".urlencode($_POST[art_title]

Can someone please help
Avatar of Om Prakash
Om Prakash
Flag of India image

Try:
$redirect = "frm_artgallery.php?artist_added=".urlencode($_POST[art_Nme])."&".urlencode($_POST[art_title]);
Avatar of Julian Hansen
You mean like this?
$redirect = "frm_artgallery.php?artist_added=".urlencode($_POST[art_Nme]) . "&image_added=" . urlencode($_POST[art_title]);

Open in new window

If this is going to be output in the browser then it should be escaped like so
$redirect = "frm_artgallery.php?artist_added=".urlencode($_POST[art_Nme]) . "&image_added=" . urlencode($_POST[art_title]);

Open in new window

SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of doctorbill

ASKER

The url that is being presented with the code above is as follows:
frm_artgallery.php?artist_added=new+artist&image_added=title

This does not work
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
If I add the %20 this works:
frm_artgallery.php?artist_added=new+artist%20&%20image_added=title
Have a look at the output from this script.  I don't know what "this works" means, but it's good to know what the programming does to the data.

<?php
$str = urlencode(' ');
var_dump($str);

Open in new window

You might also want to consider whether the plus sign is doing what you want when it's used in the URL.  Again, var_dump() is your friend!
Ray:
Your code gives the following:

frm_artgallery.php?artist_added=new+artist&title

It is missing the &image_added=title and just using &title
Sorry Ray - I have fixed it:

This works:
                  
      $redirect = $redirect
= 'frm_artgallery.php?'
. 'artist_added='
. urlencode($_POST['art_Nme'])
. '&'. 'image_added='
. urlencode($_POST['art_title'])
;
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Absolutely - point take Ray
Solution as usual
Solution
Thanks for the points! ~Ray