2012-04-21 107 views
2

我想插入數據到我的融合表是公開的。我看着https://developers.google.com/fusiontables/docs/sample_code尋求幫助,特別是http://code.google.com/p/fusion-tables-client-php/source/browse/trunk/samples/form_example.php。我下載了這個腳本所需的文件,即下載的clienlogin.php,file.php,sql.php和constants.php。該腳本正在運行,但行沒有插入,我無法找到原因。我粘貼了我的代碼(它是一個小代碼..請看看它,讓我知道我正在提交的錯誤)。本質上,我想通過用戶表單收集用戶信息後,將數據插入到融合表中。我不想使用谷歌表格。這方面的任何幫助/指示都會有幫助。插入到谷歌融合表

<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 = "[email protected]"; 
$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> 

回答

0

我懷疑這是一個權限問題,你的表。你有沒有確定你登錄的帳戶是否被設置爲該表的編輯器?檢查這個最簡單的方法是作爲表的所有者進入Fusion Tables,然後單擊右上角的共享鏈接。