post database data via curl to php
<p>I am trying to create a php file which reads the database table and posts the rows of that table to a php form via curl.</p>

<p>The following code posts just first row of the table to the php file via curl. It does not loop through all the rows of the table and post them progressively. </p>

<pre><code>&lt;?php

define('DB_HOST', 'localhost'); 
define('DB_NAME', 'dbname'); 
define('DB_USER','dbuser'); 
define('DB_PASSWORD','dbpass'); 
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error()); 
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); 


$result = mysql_query("SELECT name,contact,city FROM customers; ");

while ($row = mysql_fetch_assoc($result)) {


$parts = explode(" ", $row[name]);
$lastname = array_pop($parts);
$firstname = implode(" ", $parts);

$gmail = "@gmail.com";
$email = $firstname.$lastname.$gmail ;

$particip = "aaa" ;


$fields = array(
    'fname' =&gt; rawurlencode($firstname),
    'lname' =&gt; rawurlencode($lastname),
    'mbl' =&gt; rawurlencode($row[contact]),
    'email' =&gt; rawurlencode($email),
    'city' =&gt; rawurlencode($row[city]),
    'e' =&gt; rawurlencode($particip)  
);




//extract data from the post
//set POST variables


$url = 'http://example.com/form.php';


//url-ify the data for the POST
foreach($fields as $key=&gt;$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
$result1 = curl_exec($ch);

echo $result1;

//close connection
curl_close($ch);



}
?&gt;
</code></pre>

<p>Update : The values are being posted to the form php file. From top row to the bottom row. But getting only the first row in the database entry.</p>

<p>Is there any way to refresh the $url before posting the second row of the database data? </p>