mercredi 22 avril 2015

PHP Curl not posting data, although it is recieving

I'm trying to make an api through php curl and my client side (form submission) is receiving data from the api... it is just not posting it to the api..

 $ch = curl_init($url); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type= application/json"));
curl_setopt($ch, CURLOPT_POST, true);

// execute the request and store the return value.
$message = curl_exec($ch);

echo 'Message returned from API is:' .  $message; 

This is the code to receive the message from the API... it is returning a message so hopefully no errors there.

This is the api code (below):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>The API</title>
</head>

<body>
<?php

//date, job number, customer, worksite, duties performed, total hours spent, type of hours

$date = $_POST['date'];
$jobnumber = $_POST['jobnumber'];
$customer = $_POST['customer'];
$worksite = $_POST['worksite'];
$duties = $_POST['duties'];
$hours = $_POST['hours'];
$hourtype = $_POST['hourtype'];
$username = $_POST['username'];



$ok = true;
$error ;

//validate the inputs
if (empty($date)) {
    $ok = false;
    $error .= "Date field empty, ";
}

if (empty($jobnumber)) {
    $ok = false;
    $error .= "Job Number field empty, ";
}
if (empty($customer)) {
    $ok = false;
    $error .= "Customer field empty, ";
}

if (empty($worksite)) {
    $ok = false;
    $error .= "Worksite field empty, ";
}
if (empty($duties)) {
    $ok = false;
    $error .= "Duties field empty, ";
}
if (empty($hours)) {
    $ok = false;
    $error .= "Hours field empty, ";
}

if (empty($hourtype)) {
    $ok = false;
    $error .= "Hour type not specified, ";
}

$data = $date . ', ' . $jobnumber . ', ' . $customer . ', ' . $worksite . ', ' . $duties . ', ' . $hours . ', ' . $hourtype;
echo $data;
?>
</body>

</html>

My submit page is returning "Message returned from API is: , , , , , ,"

For the life of me I can't find what I'm doing wrong and I could really use a second set of eyes, and a second brain... lol..

Thanks everyone!

Aucun commentaire:

Enregistrer un commentaire