0

I currently collect data from a mysql table then post the data using Curl. The values are :

title : surname : email
Max     Test      max@test.com

How do i collect the data then change the feild names for post to :

MainTitle : Lastname : MainEmail
Max     Test      max@test.com

this is my current code :

$conn = mysql_connect("localhost","max","pass");
$db   = mysql_select_db("maindb",$conn);
$query = "SELECT * FROM app2 ";
$result = mysql_query($query) or die(mysql_error());

 $url = "http://test.com?"; 
 while($row = mysql_fetch_assoc($result)) {

        $input = urldecode(http_build_query( $row ));

        $ch = curl_init();                    
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);  
        curl_setopt($ch, CURLOPT_POSTFIELDS, $input); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($curl_exect, CURLOPT_HEADER, true);

        $output = curl_exec ($ch); 

        curl_close ($ch); 

        var_dump($output); 

        echo "</br>";
    }
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 23 '15 at 14:09

1 Answers1

0

There are several possible ways to rename the fields, but the easiest may be to do it within your SQL statement:

$query = "SELECT title AS `MainTitle`, surname AS `Lastname`, email AS `MainEmail` 
          FROM app2";
DOOManiac
  • 6,066
  • 8
  • 44
  • 67