Jump to content

Recommended Posts

Within my script I have:

 

$whatever = $_POST['whatever'];

$whatever2 = $_POST['whatever2'];

 

These were from a form that the user filled out.

 

Alot of stuff happens to $whatever and $whatever2 within my script, but at the end of the script I need $whatever and $whatever2 to get passed as $_POST data to http://www.someotherscript.com/script.php. This data can not be $_GET data in the URL. It must be passed as $_POST data.

 

I know how to use standard HTML forms, but I don't know how to do this. Please help.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/56754-solved-posting-within-a-script/
Share on other sites

You're submitting to a script which expects POST form data, right?  So post it using the functions named above.  The script doesn't give a rat's ass what changes the data went through.  You can define what name you wish to give the data when POSTing, and it should agree with the form elements the script expects, but you probably know that already.

ok ok, what it is is i have an email form on my website that has a radio button a user can check if they want to be added to our email list. For a long time I have been viewing the emails, and manually adding the people to my email database. I also have a host supplied form script that can add the users to the email database, and I'm trying to automate it.

$name = 'John Doe';
$email = 'johndoe@nobody.net';

//this is the array of name=>value that need to POST
array('Name'=>"$name",
        'Email'=>"$email",
'DeliveryFormat'=>'HTML',
'Password'=>'RandomNumber',
'SID'=>'{CDFEB2A7-0B0C-4541-A50B-CC975DDB114A}')

 

I've been trying, but I'm in a bit of a rush, any help would be greatly appreciated

I used curl. It was super easy. I found a PDF online that was very imformative:

 

http://www.phpit.net/article/using-curl-php/2/?pdf=yes

 

Here was the code I came up with:

 

<?php
if ($aCleanedValues['opt-in'] == 'Y'){
$name = $aAllRawValues['realname'];
$email = $aAllRawValues['email'];
$url = "http://myemaildatabase.php?ID=abcdefg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); //needed for some reason
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //so you dont see the process, it just happens before the redirect
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS,  array('Name'=>"$name",
					        'Email'=>"$email",
					        'DeliveryFormat'=>'HTML',
					        'Password'=>'RandomNumber',
					        'NewsletterListID'=>'123',
					        'JoinType'=>'Online',
					        'SID'=>'{CDFEB2A7-0B0C-4541-A50B-CC975DDB114A}')); // add POST fields
curl_exec($ch); // run the whole process
curl_close($ch);
}
?>

Yeah, you could use cURL.  In fact, I was surprised no one had mentioned it yet.  For simple stuff, I would use the stream method, though.

 

If all this is on your own site, can't you just modify the "I want your e-mails" form to directly update the database instead of redirecting the input to another form?

Yeah, you could use cURL.  In fact, I was surprised no one had mentioned it yet.  For simple stuff, I would use the stream method, though.

 

If all this is on your own site, can't you just modify the "I want your e-mails" form to directly update the database instead of redirecting the input to another form?

 

The "I want your emails" form already directly updates the database, I just wanted the "Send us an email" form to do it too. When using the "Send us an email" form, you are given a choice to subscribe to our emails, and now it automatically updates the database.

 

I could never figure out the streaming. With the information provided in the curl example above, can you show me how you would have done it?

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.