Insertion into google fusion table - google-fusion-tables

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>

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?

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.

Related

Testing Text To Speech (TTS) in browser

There is a really old blog entry from Twilio about testing the TTS in browser:
https://www.twilio.com/blog/2011/08/testing-twilios-text-to-speech-engine-using-twilio-client.html
Unfortunately it doesn't contain enough information to put a test together. It also contains a number of dead links and mentions a Github project that I can't find.
I'd really like for users to have the ability to hear what their announcement will sound like prior to firing off the form and starting the phone calls.
I use Lasso (which fires off CURL requests to the Twilio REST API), but any kind of tutorials or hints would be appreciated.
If you set up a demo account on Twilio and use Glitch online php tester (https://glitch.com/edit/#!/php-poc) or a local environment you can create a workable example like I did. You will need to fill in the empty strings to correspond to your app name. Search for TwiML in the website to get to the right section to set the right url of your server that TWilio will call upon request to read content (xml). In my case url was http://<server>/?incoming-call.php tested on Glitch.
You need to grab the Twilio PHP SDK and include the Services/Twilio/Capability.php from https://github.com/twilio/starter-php in your server code.
<?php
require __DIR__ . '/../vendor/autoload.php';
$url = [];
$url = explode('?', $_SERVER['REQUEST_URI']);
if (count($url) == 2 && $url[1] == 'incoming-call.php')
{
header('Content-type: text/xml');
$response = new Twilio\Twiml;
$dialogue = trim($_REQUEST['dialogue']);
$voice = (int) $_REQUEST['voice'];
if (strlen($dialogue) == 0)
{
$dialogue = 'Please enter some text to be spoken.';
}
if ($voice == 1)
{
$gender = 'man';
}
else
{
$gender = 'woman';
}
$response->say($dialogue);
echo $response;
exit;
}
require_once('Services/Twilio/Capability.php');
$accountsid = ''; // YOUR TWILIO ACCOUNT SID
$authtoken = ''; // YOUR TWILIO AUTH TOKEN
$fromNumber = ''; // PHONE NUMBER CALLS WILL COME FROM
$APP_SID = '';
$token = new Services_Twilio_Capability($accountsid, $authtoken);
$token->allowClientOutgoing($APP_SID);
?>
<html>
<head>
<title>Text-To-Speech</title>
<script type="text/javascript" src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript"
src="//media.twiliocdn.com/sdk/js/client/v1.5/twilio.js"></script>
<script type="text/javascript">
Twilio.Device.setup("<?php echo $token->generateToken();?>",{"debug":true});
$(document).ready(function() {
$("#submit").click(function() {
speak();
});
});
function speak() {
var dialogue = $("#dialogue").val();
var voice =
$('input:radio[name=voice]:checked').val();
Twilio.Device.connect({ 'dialogue' :
dialogue, 'voice' : voice });
}
</script>
</head>
<body>
<p>
<label for="dialogue">Text to be spoken</label>
<input type="text" id="dialogue" name="dialogue"
size="50">
</p>
<p>
<label for="voice-male">Male Voice</label>
<input type="radio" id="voice-male" name="voice"
value="1" checked="checked">
<label for="voice-female">Female Voice</label>
<input type="radio" id="voice-female" name="voice"
value="2">
</p>
<p>
<input type="button" id="submit" name="submit"
value="Speak to me">
</p>
</body>
</html>

how to display post variables in email body by PHPmailer

Can any one help me to integrate a form with PHPMailer. I have following form.
<form method="POST">
<p>Name:<input type="text" name="name" size="30"></p>
<p>Email Address:<input type="text" name="email" size="30"></p>
<input type="submit" name="submit" value="Submit">
</form>
I just need to display POST variables in my receiving email's body. I have search and refer alot and spend hours in it, everyone clarifies it with high level explanation. As i am not a programmer can anyone explain me how can i do this with simple explanation. I just done a method as follows but it did'nt work.
$name = $_POST['name'];
$email = $_POST['email'];
$mail->Body = "
<html>
<h2><b>".$name." ".$email."</b></h2>
</html>";
When i tried the above method i am getting error in this line '$name = $_POST['name'];'. The error message is: Notice: Undefined index:' I think i am wrong with my placing order of codes.
Thanks in advance!
<?php
if(array_key_exists("name",$_POST) && $_POST["name"] != "" && array_key_exists("email",$_POST) && $_POST["email"] != ""){
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mail#gmail.com', 'Manager');
$mail->addAddress('mail#gmail.com', 'Administrator'); // Add a recipient
$name = $_POST['name'];
$email = $_POST['email'];
$mail->Body = "<h2><b>".$name." ".$email."</b></h2>";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
} else {
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST">
<p>Name:<input type="text" name="name" size="30" required></p>
<p>Email Address:<input type="email" name="email" size="30" required></p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
}
?>

What can i do to find a Broken Link?

I am working on a website and the owner of the website found three broken links (through a software/tool of IBM) in the given page. I removed two broken links but there is one broken link left. I searched the whole web page but I am unable to find it.
What can I do to find that link?
Here is the code of the page:
<?php
session_start();
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Legal Aid Service Monitoring System</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery3.js"></script>
<script type="text/javascript" src="js/jquery4.js"></script>
<script type="text/javascript" src="js/jquery5.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#login-form").validate({
debug: false,
rules: {
email: {
required: true,
email: true
}
},
messages: {
email: "Please enter a valid email.",
},
});
});
</script>
<style type="text/css">
label.error { width: 250px; color: red;}
</style>
</head>
<body>
<?php
if($_POST['login'])
{
require_once("config.php");
if($_POST['user_type']=='admin')
{
$user=mysql_real_escape_string($_POST['uname']);
$password=md5($_POST['pwd']);
$sql=mysql_query("select id from admin where username='$user' and password='$password'");
$count=mysql_num_rows($sql);
if($count>0)
{
$row=mysql_fetch_array($sql);
$_SESSION['admin']=$row['id'];
$date=date('d-m-y');
$time_now=mktime(date('h')+0,date('i')+00,date('s'));
$time=date('h:i:s',$time_now);
$login=mysql_query("insert into user_login (user_id, login_date, login_time) values ('$_SESSION[admin]', '$date', '$time')");
header('location: administrator');
}
else
{
?>
<script type="text/javascript"> alert('Incorrect Username and Password.');</script>
<?php
}
}
else if($_POST['user_type']=='advo')
{
$user=mysql_real_escape_string($_POST['uname']);
$password=md5($_POST['pwd']);
$sql=mysql_query("select id, status from advocates where email='$user' and password='$password'");
$count=mysql_num_rows($sql);
$row=mysql_fetch_array($sql);
if($count>0 and $row['status']=='1')
{
$_SESSION['advocate']=$row['id'];
$date=date('d-m-y');
$time_now=mktime(date('h')+0,date('i')+00,date('s'));
$time=date('h:i:s',$time_now);
$login=mysql_query("insert into advo_login (advo_id, login_date, login_time) values ('$_SESSION[advocate]', '$date', '$time')");
header('location: advocate');
}
else
{
if($row['status']=='0')
{
?>
<script type="text/javascript">alert('Your account has been blocked by admin.');</script>
<?php
}
else
{
?>
<script type="text/javascript">alert('Incorrect Username and Password.');</script>
<?php
}
}
}
}
?>
<div class="main" id="main">
<div id="headerbg">
<div id="header"></div>
</div>
<div id="center">
<div class="style1" id="centerright">
<div id="centerup">
<table width="514" border="0" align="center">
<tr>
<td><h3>Welcome to Legal Aid Service Monitoring System</h3></td>
</tr>
</table>
</div>
<div id="centerdown">
<div id="loginbg">
<form id="login-form" name="login-form" method="post" action="">
<table width="500" border="0" >
<tr><td></td>
<td height="30">
<input type="radio" name="user_type" value="advo" checked="checked" />Advocate
<input type="radio" name="user_type" value="admin" />Administrator
</td>
</tr>
<tr>
<td width="50"><span class="style5">Username:</span></td>
<td width="236"><label>
<input type="text" name="uname" class="required input" size="30" />
</label></td>
</tr>
<tr>
<td><span class="style5">Password:</span></td>
<td><label>
<input type="password" name="pwd" id="pwd" class="required input" size="30"/>
</label></td>
</tr>
<tr>
<td></td>
<td><label>
<input type="submit" class="style1loginbg" name="login" id="button" value="Login" />
</label></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
If you have Firebug or somekind of similar console access you could run this snippet of code on a page by page basis:
jQuery(function(){
var getHost = function(url){
url = String(url);
if ( (url.substr(0,5) == 'http:') || (url.substr(0,6) == 'https:') ) {
return url.split('/').slice(0,3).join('/');
}
else {
return null;
}
}
var host = getHost(window.location);
jQuery('a').each(function(){
var link = $(this), href = link.attr('href'), hst = getHost(href);
if ( hst === host || hst === null ){
jQuery.ajax({
url: href,
error: function(){
link.css('border', '5px solid red');
}
});
}
else {
link.css('border', '5px solid purple');
window.open( link,'_blank');
}
});
});
It should highlight with a red border any internal links that fail to load via ajax, and highlight any external links with purple (at which point it'll try and open the external link in a new tab for you to visually check). Obviously this might go a bit mad if your page has many external links...
It would be far better to actually get some link checking software - search Google - and run that... as that should act in a way that's know as 'Spidering a site'. Basically it would step through each of your pages and return a report of all the broken links found (you'd have to make sure the software supported cookies seeing as the site you've given requires authorisation).
One further thing to be aware of is that it isn't just links that can cause software to fire a 'broken link' error. You may find that some of your page resources trigger a 404... i.e. you should check all your images, css and js to make sure they load.
This suggestion doesn't solve the question, but I believe it's worth mentioning that the WebDev toolbar (http://chrispederick.com/work/web-developer/ (a firefox add-on) can at least help here.
It can display all links in a webpage and highlight and show all anchors. This can help the developer to 'scan' a website for out-of-place links. )
When installed, choose INFORMATION ยป and either
Display anchors
Display page information
Display link information
You can use a tool like phantomjs or protractor for this. One working tool can be found on https://github.com/ashittheone/broken-links-log.
this repository can be used to log all broken links upto 5 depth of anywebsite.
Although in a later version the depth is expected to be coming customizable

PHPmailer on uploaded website

does anybody know how i get phpmailer to work on an uploaded website.
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$body = "You have been added to the University of Portsmouth project
database. Your password is
'".$_POST['Password']."'
And your username is
'".$_POST['Username']."'
please click the link below, login to the website, select account settings and change
the password to become verified";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tsl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 25; // set the SMTP port
$mail->Username = "projectnateabiola#gmail.com"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->From = "projectnateabiola#gmail.com";
$mail->FromName = "Nathan Abiola";
$mail->Subject = "You have been added to the project database, this email is important";
$mail->AltBody = "Please click"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("projectnateabiola#gmail.com","Webmaster");
$mail->AddAddress($_POST['Email'],"First Last");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
The code works when offline, but once i upload it i get the following error when i submit it. Am i missing something like you cant use phpmailer online. Does any body have any potential alternatives. Thanks for any possible help.
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
I use this for my sites. It is a form on a webpage that calls a php file to send an email. I have found that it has issues sometimes on College servers so keep that in mind.
create a file called mailto.php and paste this in (note that you need to put the correct email address in)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Submitted!</title>
</head>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "PUT YOUR EMAIL ADDRESS HERE", "Subject: $subject",
$message, "From: $email" );
echo "Your message has been sent successfully!";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
Then put this in the body of your html file
<form name="formcheck" onsubmit="return formCheck(this);" action="mailto.php" method="post">
<br />
E-mail: <input type="text" name="email" id="email" size="42" />
<br />
<br />
<br/>
Subject: <input type="text" name="subject" id="subject" size="42" />
<br />
<br />
<br />
Message:
<br />
<textarea rows="5" cols="40" name="message" id="message"></textarea>
<br />
<br />
<input type="submit" onClick="return checkmail(this.form.email)" value="Submit" /><input type="reset" />
</form>
Hope this helps and if anyone has suggestions on how to make this better let me know :)

Ajax Single Field Submission in form

I've created an order form, of which has a large array of fields. I'm now adding coupon functionality so that we can start to give customers discount codes etc.
What's the best way of submitting a single field (the coupon code) using ajax after a "apply coupon" button has been clicked so that the price can be updated on the front end probably using UJS(?) - obviously the final price calculation would happen on the backend?
Cheers.
I would recommend using a JS framework to do Ajax requests. If you JQuery, then you can use the example given to understand how to do a simple post.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form action="/" id="searchForm">
<input type="text" name="s" placeholder="Search..." />
<input type="submit" value="Search" />
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
<script>
/* attach a submit handler to the form */
$("#searchForm").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
term = $form.find( 'input[name="s"]' ).val(),
url = $form.attr( 'action' );
/* Send the data using post and put the results in a div */
$.post( url, { s: term },
function( data ) {
var content = $( data ).find( '#content' );
$( "#result" ).empty().append( content );
}
);
});
</script>
</body>
</html>

Resources