Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Using Post

  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    Using Post

    Alright.. this seems simple but I can't figure it out.

    I made a <form> that uses POST into an external URL.. but how would i make it so that i can POST directly into the URL?

    this is my system: When a user on my site completes an offer, it goes to my Postback URL and inserts it into my sql database.. then I want it to take those same values I used to insert into my SQL to POST it into an external website. I have all the values for the POST, I just need to know how to be able to post into that site automatically without the use of a button so it can just do everything automatically.

    I am drawing a complete blank. Can i send a POST without a form?
    Last edited by markman641; 02-01-2012 at 02:45 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by markman641 View Post
    Alright.. this seems simple but I can't figure it out.

    I made a <form> that uses POST into an external URL.. but how would i make it so that i can POST directly into the URL?

    this is my system: it calls on a script to do a bunch of SQL tasks, then at the end of that it takes the values and uses POST into the URL... how would I make it automatically POST without having to use an ok/send/submit button?

    I am drawing a complete blank. Can i send a POST without a form?
    Wrong forum btw

    To answer, POST is just a method of passing values. Using a form is the most common method, but you can send POST data several other ways - via AJAX or PHP libraries (cURL as one). Which one you choose is up to you.

    Sounds like AJAX is probably your best bet.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    markman641 (02-02-2012)

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    Wrong forum btw

    To answer, POST is just a method of passing values. Using a form is the most common method, but you can send POST data several other ways - via AJAX or PHP libraries (cURL as one). Which one you choose is up to you.

    Sounds like AJAX is probably your best bet.
    I'm glad that made sense to you. I updated the OP to make a little more sense. Ill look up on google how to do AJAX. Could this be added to my postback script so it wont take it off the page?
    Last edited by markman641; 02-01-2012 at 02:49 AM.

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Now you've edited your post, cURL sounds like a better option. Tonnes of examples and info on the php manual.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    markman641 (02-02-2012)

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    Now you've edited your post, cURL sounds like a better option. Tonnes of examples and info on the php manual.
    I dont know cURL at all.. ill try my best tho.

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    It's pretty simple - the PHP manual has plenty of discussion and examples on it.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    markman641 (02-02-2012)

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    It's pretty simple - the PHP manual has plenty of discussion and examples on it.
    what PHP manual?

  • #8
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    It's pretty simple - the PHP manual has plenty of discussion and examples on it.
    What's wrong with this?

    PHP Code:
    <?

    //set POST variables
    $url 'http://www3.cbox.ws/box/index.php?boxid=3239282&boxtag=wcwcp8&sec=submit';
    $message1 'testinggg';
    $key '1983ffec3c997fd3739fef1d4cc46f99';
    $nme 'MoneyBot';
    $pic 'http://cdn.techsling.com/wp-content/uploads/2011/02/windowssecuritycentre1.png';
    $ekey 'e6eba3f75fec9100f4e33dfe609c89ff';
    $lvl '4';
    $fields = array(
                            
    'key'=>urlencode($key),
                            
    'nme'=>urlencode($nme),
                            
    'pic'=>urlencode($pic),
                            
    'ekey'=>urlencode($ekey),
                            
    'lvl'=>urlencode($lvl),
                            
    'pst'=>urlencode($message1),
                    );

    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&amp;'; }
    rtrim($fields_string,'&amp;');

    //open connection
    $ch curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

    //execute post
    $result curl_exec($ch);

    //close connection
    curl_close($ch);

    ?>
    Last edited by markman641; 02-01-2012 at 03:47 AM.

  • #9
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by markman641 View Post
    What's wrong with this?

    PHP Code:
    <<?

    //set POST variables
    $url 'http://www3.cbox.ws/box/index.php?boxid=3239282&boxtag=wcwcp8&sec=submit';
    $message1 'testinggg';
    $key '1983ffec3c997fd3739fef1d4cc46f99';
    $nme 'MoneyBot';
    $pic 'http://cdn.techsling.com/wp-content/uploads/2011/02/windowssecuritycentre1.png';
    $ekey 'e6eba3f75fec9100f4e33dfe609c89ff';
    $lvl '4';
    $fields = array(
                            
    'key'=>urlencode($key),
                            
    'nme'=>urlencode($nme),
                            
    'pic'=>urlencode($pic),
                            
    'ekey'=>urlencode($ekey),
                            
    'lvl'=>urlencode($lvl),
                            
    'pst'=>urlencode($message1),
                    );

    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&amp;'; }
    rtrim($fields_string,'&amp;');

    //open connection
    $ch curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

    //execute post
    $result curl_exec($ch);

    //close connection
    curl_close($ch);

    ?>
    What do you mean? Is it giving you any error? You should check for a false $result, then do something with curl_error($ch).
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    markman641 (02-02-2012)

  • #10
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    What do you mean? Is it giving you any error? You should check for a false $result, then do something with curl_error($ch).
    it just gives me a blank white page.

  • #11
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    here is the code of the FORM that i made..

    PHP Code:
    <body onload="$('cbox').submit()">
    <
    form name="cbox" target="cboxmain3-3239282" action="http://www3.cbox.ws/box/index.php?boxid=3239282&boxtag=wcwcp8&sec=submit" method="post" class="cfrm" onsubmit="return do_post();" _lpchecked="1">
    <
    table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
    <
    tbody><tr>
    <
    td align="right"><a href="index.php?boxid=3239282&amp;boxtag=wcwcp8&amp;sec=main" target="cboxmain3-3239282" onclick="return do_refresh();" id="rf">refresh</a>&nbsp;</td>
    </
    tr><tr>
    <
    td colspan="2" height="100%" id="tblmid" align="center" valign="center">
    <
    input type="hidden" name="key" value="1983ffec3c997fd3739fef1d4cc46f99">        <input type="text" name="nme" value="MoneyBot">
    <
    input type="hidden" name="eml" value=""> <input type="hidden" name="pic" value="http://cdn.techsling.com/wp-content/uploads/2011/02/windowssecuritycentre1.png"><input type="hidden" name="ekey" value="e6eba3f75fec9100f4e33dfe609c89ff">
    <
    input type="hidden" name="lvl" value="4">
    <
    input type="text" maxlength="500" name="pst" autocomplete="off" size="9" value="message" class="frmtb" onfocus="frmfocus(this, 'message')" onblur="frmblur(this, 'message')" style="width: 185px; "><input type="submit" value="Go" name="sub" class="frmbtn" style="height: 19px; width: 23px; "></td></tr>
    <
    tr><td align="center" colspan="2">
    <
    div align="right">
    <
    div style="position:relative;width: 16px; height: 11px; overflow: hidden;float: left;cursor:pointer;" onclick="togglesnd()"><img src="snd2.png" id="sndctrl" width="48" height="11" style="position: relative; left: -32px; "></div>&nbsp;&nbsp;
    <
    a href="JavaScript:pop('help', 320, 300, 1)">help</a>
    </
    div></td></tr>
    </
    tbody></table>
    </
    form>
    </
    body
    then i took those input values and put it in the cURL

  • #12
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by markman641 View Post
    it just gives me a blank white page.
    Did you check for a false $result, and then echo (or kill the script with die(curl_error($ch))) curl_error($ch)? That will, like mysql_error(), hold the error message from the cURL transaction if there was one - PHP will not report it implicitly.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    markman641 (02-02-2012)

  • #13
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    Did you check for a false $result, and then echo (or kill the script with die(curl_error($ch))) curl_error($ch)? That will, like mysql_error(), hold the error message from the cURL transaction if there was one - PHP will not report it implicitly.
    Like I said i have no clue about any of this -.- I'm sorry i just dont understand.
    It seems like it would be SO easy just to POST to an external URL with my values without a form.
    could i just make it go to the form page, fill the values using get and have an autosubmit form?
    i really dont know i cant think straight :P
    Last edited by markman641; 02-01-2012 at 04:32 AM.

  • #14
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by markman641 View Post
    Like I said i have no clue about any of this -.- I'm sorry i just dont understand.
    It seems like it would be SO easy just to POST to an external URL with my values without a form.
    could i just make it go to the form page, fill the values using get and have an autosubmit form?
    i really dont know i cant think straight :P
    Lol, you just need to read what I'm saying properly . I'm asking you to put some error reporting in, so we can see what's going wrong.
    PHP Code:
    Rest of your code up to this point

    //execute post 
    $result curl_exec($ch); 

    // Do some error reporting. $result will be FALSE if curl_exec() failed for some reason
    if(!$result){
        echo 
    'cURL Error: '.curl_error($ch);
    }

    //close connection 
    curl_close($ch); 

    ?> 
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    markman641 (02-02-2012)

  • #15
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by BluePanther View Post
    Lol, you just need to read what I'm saying properly . I'm asking you to put some error reporting in, so we can see what's going wrong.
    PHP Code:
    Rest of your code up to this point

    //execute post 
    $result curl_exec($ch); 

    // Do some error reporting. $result will be FALSE if curl_exec() failed for some reason
    if(!$result){
        echo 
    'cURL Error: '.curl_error($ch);
    }

    //close connection 
    curl_close($ch); 

    ?> 
    Came up with a blank page again.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •