Jump to content

add %20 to my url string


ballhogjoni

Recommended Posts

I am pulling these variables from my mysql db and posting them into this url string. Some vaiables have spaces like the address, how do I automatically encode the url to put a %20 in the place of the space? [code]https://www.XXXXXX.com/auto/api.php?partner_login=$username&partner_password=$password&test=TRUE&command=$command&user_id=$user_id&service=\"code=DS,frequency=M,action=add,renewal_billed_to=U,trial=14\"&output=php&phone=$phone&first_name=$first&last_name=$last&bill_address1=123 address&bill_address2=&bill_city=$city&bill_state=$state&bill_postal=$zipcode&bill_country=US&username=foousername&password=foopassword&cc_num=$ccnumber&cc_exp=$expyear-$expmonth&email=$email";[/code]

this is my code i am trying to make this work for:
[code]mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query("SELECT first, last, email, address, city, state, zipcode, phone FROM articlecash ORDER BY id DESC");

$result2 = mysql_query("SELECT ccnumber, expyear, expmonth FROM articlecashccinfo ORDER BY id DESC");

$result1 = mysql_fetch_array($result);
$result3 = mysql_fetch_array($result2);

mysql_close();

$phone = $result1['phone'];
$first = $result1['first'];
$last = $result1['last'];
$email = $result1['email'];
$address = $result1['address'];
$city = $result1['city'];
$state = $result1['state'];
$zipcode = $result1['zipcode'];
$ccnumber = $result3['ccnumber'];
$expyear = $result3['expyear'];
$expmonth = $result3['expmonth'];
$username = 'XXXXX';
$password = 'XXXXX';
$command = "user.configure";
$user_id = "NEW";
$url = "https://www.XXXX.com/auto/api.php?partner_login=$username&partner_password=$password&test=TRUE&command=$command&user_id=$user_id&service=\"code=DS,frequency=M,action=add,renewal_billed_to=U,trial=14\"&output=php&phone=$phone&first_name=$first&last_name=$last&bill_address1=$address&bill_address2=&bill_city=$city&bill_state=$state&bill_postal=$zipcode&bill_country=US&username=foousername&password=foopassword&cc_num=$ccnumber&cc_exp=$expyear-$expmonth&email=$email";

$ch = curl_init();
curl_setopt( $ch , CURLOPT_URL , $url); //the url
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable 
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s 
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
$ret = curl_exec($ch);
curl_close($ch);

echo $ret;

?>[/code]
Link to comment
Share on other sites

Have you checked the value of $url after it has been encoded?  Stick a...

[code]
die( $url );
[/code]

after the

[code]
$url = rawurlencode( ... );
[/code]

and see if it's value is as expected.  If it is, then maybe the problem lies with the destination script or the use of curl.  Not a curl expert... :)
Link to comment
Share on other sites

Are you sure the api.php script accepts GET variables?  I notice you've got CURLOPT_POST set, but no postdata sent.

Maybe working from an example like [url=http://www.phpfreaks.com/tutorials/49/2.php]http://www.phpfreaks.com/tutorials/49/2.php[/url] would help.
Link to comment
Share on other sites

I just echoed my $url, and it comes up like this:

http%3A%2F%2Fwww.somedomain.com%2Fauto%2Fapi.php%3Fpartner_login%3Dmyusername%26partner_password%3Dmypassword%26test%3DFALSE%26command%3Duser.configure%26user_id%3DNEW%26service%3D%22code%3DDS%2Cfrequency%3DM%2Caction%3Dadd%2Crenewal_billed_to%3DU%2Ctrial%3D14%22%26output%3Dphp%26phone%3D801-472-6981%26first_name%3DChris%26last_name%3DGunnels%26bill_address1%3D225+Timber+Wolf+Trail%26bill_address2%3D%26bill_city%3DGriffin%26bill_state%3DGA%26bill_postal%3D30224%26bill_country%3DUS%26username%3Dfoousername%26password%3Dfoopassword%26cc_num%3D41111111111111111%26cc_exp%3D2007-01%26email%3Dsomeemail%40yahoo.com

can someone show me how to just add %20 in the spaces. right now it is adding all kinds of stuff. i am using urlencode(); The url is supposed to look like this:

http://www.someurl.com/auto/api.php?partner_login=myusername&partner_password=mypassword&test=FALSE&command=user.configure&user_id=NEW&service="code=DS,frequency=M,action=add,renewal_billed_to=U,trial=14"&output=php&phone=801-472-6981&first_name=Chris&last_name=Gunnels&bill_address1=225[color=red]%20[/color]Timber[color=red]%20[/color]Wolf[color=red]%20[/color]Trail&bill_address2=&bill_city=Griffin&bill_state=GA&bill_postal=30224&bill_country=US&username=foousername&password=foopassword&cc_num=41111111111111111&cc_exp=2007-01&email=someemail@yahoo.com
Link to comment
Share on other sites

When I use rawurlencode(); I get:

https%3A%2F%2Fwww.someurl.com%2Fauto%2Fapi.php%3Fpartner_login%3Dmyusername%26partner_password%3Dmypass%26test%3DFALSE%26command%3Duser.configure%26user_id%3DNEW%26service%3D%22code%3DDS%2Cfrequency%3DM%2Caction%3Dadd%2Crenewal_billed_to%3DU%2Ctrial%3D14%22%26output%3Dphp%26phone%3D801-472-7895%26first_name%3DChris%26last_name%3DGunnels%26bill_address1%3D225%20Timber%20Wolf%20Trail%26bill_address2%3D%26bill_city%3DGriffin%26bill_state%3DGA%26bill_postal%3D30224%26bill_country%3DUS%26username%3Dfoousername%26password%3Dfoopassword%26cc_num%3D41111111111111111%26cc_exp%3D2007-01%26email%3Dsomeemail%40yahoo.com
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.