2

I want to insert data into my fusion table which is public . I looked out at https://developers.google.com/fusiontables/docs/sample_code for help specifically http://code.google.com/p/fusion-tables-client-php/source/browse/trunk/samples/form_example.php . I downloaded the necessary files for this script to run i.e. downloaded clienlogin.php , file.php , sql.php and constants.php. The script is running but rows are not getting inserted and I am not able to find the reason . I have pasted my code ( its a small code .. please have a look at it and let me know the error I am commiting). Essentially I want to insert data into my fusion table after collecting user info through user forms . I don't want to use google forms. Any kind of help / pointers in this direction would be helpful.

<html>

<?php

include('D:\xampp\htdocs\itpold\clientlogin.php');
include('D:\xampp\htdocs\itpold\sql.php');
include('D:\xampp\htdocs\itpold\file.php');

// Table id
$tableid = 3544282;

//Enter your username and password
$username = "ABCD@gmail.com";
$password = "XYZ";


$token = ClientLogin::getAuthToken($username, $password);
$ftclient = new FTClientLogin($token);

// If the request is a post, insert the data into the table
if($_SERVER['REQUEST_METHOD'] == 'POST') {
// Insert form data into table
  $insertresults = $ftclient->query(SQLBuilder::insert($tableid, 
    array('Name'=> $_POST['Name'],
    'Location' => $_POST['Location'])));
  $insertresults = explode("\n", $insertresults);
  $rowid1 = $insertresults[1];
  echo $rowid1 ;
}

?>

<head>
<title>Simple Form Example</title>

<style>
  body { font-family: Arial, sans-serif; }

</style>


<script type="text/javascript">

// Simple form checking.
function check_form() {
  if(document.getElementById('Name').value == '' ||
    document.getElementById('Location').value == '') {

      alert('Name and location required.');
      return false;
  } 
  return true;
}


</script>
</head>

<body >

<h1>Simple Form Example</h1>

<h2>Insert data</h2>
<form method="post" action="forms.php" onsubmit="return check_form();">
  Name: <input type="text" name="Name" id="Name" /><br />
  Result: <input type="text" name="Location" id="Location" /><br />

  <input type="submit" value="Submit" />
</form>

<h2>Table data</h2>
<p>
<?php
// Show the data from table
$table_data = $ftclient->query(SQLBuilder::select($tableid));
$table_data = explode("\n", $table_data);
for($i = 0; $i < count($table_data); $i++) {
  echo $table_data[$i] . '<br />';
} 
?>
</p>
</body>
</html>
Moh
  • 21
  • 2

2 Answers2

0

Often, the server is not able to send requests to secure URLs. See the following StackOverflow post for some ideas on how to fix the problem:

Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?

Community
  • 1
  • 1
Kathryn Hurley
  • 1,094
  • 6
  • 9
0

I suspect that this is a permissions problem with your table. Have you made sure that the account your are logging in with is set up as an editor for this table? The easiest way to check this is to go into Fusion Tables as the owner for the table, and click the share link in the upper right hand corner.

javram
  • 2,635
  • 1
  • 13
  • 18