ballhogjoni Posted January 15, 2007 Share Posted January 15, 2007 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 https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/ Share on other sites More sharing options...
emehrkay Posted January 15, 2007 Share Posted January 15, 2007 http://www.phpfreaks.com/phpmanual/page/function.urlencode.html Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160848 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 I have tried that. I must not know where to put it though. Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160850 Share on other sites More sharing options...
bqallover Posted January 15, 2007 Share Posted January 15, 2007 Instead of...[code]$url = "https://www.XXXX... ";[/code]use[code]$url = rawurlencode( "http://.... " );[/code]That should give you %20 for spaces, unline urlencode() which will give you +. Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160851 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 I hate to be a pain, but that dint work either. I am having the hardest time iwth this api stuff. Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160853 Share on other sites More sharing options...
bqallover Posted January 15, 2007 Share Posted January 15, 2007 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 https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160857 Share on other sites More sharing options...
bqallover Posted January 15, 2007 Share Posted January 15, 2007 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 https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160861 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 I am pretty sure it accepts GET variables because I can place the url into a browser and it works perfectly, all I need to do is manually type the values of the variables in place of the variables. Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160868 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 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.comcan 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 protected] Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160871 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 any responses Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160893 Share on other sites More sharing options...
Hypnos Posted January 15, 2007 Share Posted January 15, 2007 You're using urlencode. You want rawurlencode.http://us2.php.net/manual/en/function.rawurlencode.phphttp://us2.php.net/manual/en/function.urlencode.phpurlencode - Converts ' ' to '+'.rawurlencode - Converts ' ' to '%20'. Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160896 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 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 https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160899 Share on other sites More sharing options...
Hypnos Posted January 15, 2007 Share Posted January 15, 2007 Don't use it on the entire url. Use it on the vars.$first = rawurlencode($result1['first']);$last = rawurlencode($result1['last']); Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-160905 Share on other sites More sharing options...
ballhogjoni Posted January 15, 2007 Author Share Posted January 15, 2007 Thx Hypnos,that worked perfectly! Link to comment https://forums.phpfreaks.com/topic/34188-add-20-to-my-url-string/#findComment-161070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.