Hi, having a bit of problem. My goal is to log into a website using cURL. Once logged in, I need to go to a page which only logged in users can view. This page contains another form, and I need to then post data to this new form and collect the result.

At the moment, I can login using
Code:
function login(){
    $accountCode = 'myCode';
    $username = 'myUsername';
    $password = 'myPassword';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://test.com'); 
    curl_setopt ($ch, CURLOPT_POST, 1);
    $postData='
    rememberMe=No
    &AccountCode='.$accountCode.'
    &Username='.$username.'
    &Password='.$password.'
    &Username='.$username;
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $store = curl_exec ($ch);
    return $ch;
}
so now if I do $ch=login(); I am returned a logged in instance. Now say the search form on the logged in page is located at www.test.com/search, I have the following code
Code:
function submit_search($Url,$ch){
    $urltopost = $Url;
    $datatopost = array (
        "rdoTrip" => "rr",
        "txtDepartureCity" => "(LHR)London,London Heathrow,United Kingdom",
        "txtArrivalCity" => "(LAX)Los Angeles,Los Angeles Intl.,United States",
        "txtDepartDate" => "31 Oct 2013",
        "txtReturnDate" => "26 Nov 2013",
        "ddlAdult" => "1",
        "ddlCabinClass" => "Business",
        "rdoAllFlights" => "All",
    );

    $ch = curl_init ($urltopost);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $returndata = curl_exec ($ch);
    return $returndata;
}
I then change the initial call to
Code:
$ch=login();
$test=submit_search('http://www.test.com/search', $ch);
echo $test;
I know I am logged in successfully, but the second submit doesnt seem to work. Am I on the right tracks or am I doing something completely wrong here?

Thanks