我想将数据插入到我的公开融合表中。我查看了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 = "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>