1

I have problem when excecute the exec function in while loop
I want to transfer xml file to server the problem is the transfer to server is success but the data xml is same at all, the data is still the first xml data
are the exec action is cannot be run in while condition ? or i must clear something before run the next while ?

mysql_connect("someaddress","root","somepass");
mysql_select_db("somedatabase");

    $t_data = mysql_query("SELECT * FROM inbox_hmis WHERE ordernumber = '01' AND status = 'false'");
    while($data = mysql_fetch_array($t_data)){

    $un_id_sms = $data['id_sms'];
    echo "$un_id_sms";
        $xmlget = "/var/www/sms/basedata/$un_id_sms.xml";
                        exec("curl -d @$xmlget http://apps.dhis2.org/demo/api/dataValueSets -H Content-Type:application/xml -u admin:password", $output);
                        $outx = $output[0];

        $outx_r = str_replace("'", '"', $outx);

        echo "$outx_r | ";
    }

$un_ind_sms is unique id and the name of xml file
$outx_r is the xml data

5
  • 3
    why use command line curl and not the php curl library? Commented Jul 11, 2013 at 3:38
  • that is standard from my client Commented Jul 11, 2013 at 3:40
  • 2
    @OkiPrasastio, Your client is insane. Commented Jul 11, 2013 at 3:41
  • Is there a reason for your client to ask you to write a program but tell you how to do it? Commented Jul 11, 2013 at 3:41
  • @brad i concur....this code is f'd Commented Jul 11, 2013 at 3:42

1 Answer 1

1

You are not resetting the content of variable $output before calling exec. E.g.

unset($output); // as recomended in php docs

Before the exec call will fix your problem.

As stated in exec documentation if the array of lines already contains data, then the new result will be appended to it.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep. PHP Document: "...Note that if the array already contains some elements, exec() will append to the end of the array...".
maybe because $output is array of lines, you only output the first one. $outx=join("\n",$output) will output everything and maybe print what is expected?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.