Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
92b70e632b | |||
c81937d6a5 | |||
f451850601 | |||
3bc6a56516 | |||
536af5f9c5 | |||
e5bdf2cc2c |
@@ -7,9 +7,11 @@
|
||||
<body>
|
||||
<div id="root">
|
||||
<h1>Link Shortener</h1>
|
||||
<form id="form" action="result.js">
|
||||
<form id="form" method="GET" action="result.php" onsubmit="return validate()">
|
||||
|
||||
<!-- <form id="form"> -->
|
||||
<label for="url">URL:</label><span class="mandatory">*</span>
|
||||
<input type="text" name="url" id="URL" value="example.com" required><br><br>
|
||||
<input type="text" name="url" id="URL" value="https://example.com" required><br><br>
|
||||
|
||||
<label for="labels">GLink:</label><span class="mandatory">*</span>
|
||||
<label for="GLink" id="labels" class="glink">glink.zip/</label><input type="text" name="glink" id="GLink" class="glink" value="exampleWebsite" required>
|
||||
|
19
index.js
19
index.js
@@ -1,7 +1,7 @@
|
||||
const submit = document.getElementById("button");
|
||||
submit.addEventListener('click', validate);
|
||||
function validate(e) {
|
||||
e.preventDefault();
|
||||
//const submit = document.getElementById("button");
|
||||
//submit.addEventListener('click', validate);
|
||||
function validate() {
|
||||
// e.preventDefault();
|
||||
|
||||
const url = document.getElementById("URL");
|
||||
const glink = document.getElementById("GLink");
|
||||
@@ -48,7 +48,13 @@ function validate(e) {
|
||||
error.setAttribute('aria-hidden', true);
|
||||
error.setAttribute('aria-invalid', false);
|
||||
console.log("Valid");
|
||||
return valid;
|
||||
|
||||
return valid;
|
||||
|
||||
/* var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open('GET','result.php',true);
|
||||
xmlhttp.send();
|
||||
console.log(xmlhttp.responseText);*/
|
||||
} else {
|
||||
|
||||
/*flag*/
|
||||
@@ -62,6 +68,7 @@ function validate(e) {
|
||||
url.classList.add("invalid");
|
||||
error.setAttribute('aria-hidden', false);
|
||||
error.setAttribute('aria-invalid', true);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
console.log('Beginning database execution');
|
||||
|
||||
const cassandra = require('cassandra-driver');
|
||||
|
||||
const client = new cassandra.Client({
|
||||
@@ -5,4 +7,8 @@ const client = new cassandra.Client({
|
||||
keyspace: 'glink',
|
||||
});
|
||||
|
||||
const query =
|
||||
const query = 'SELECT name FROM data WHERE id = ?';
|
||||
|
||||
console.log(query);
|
||||
|
||||
client.execute(query, [5]).then(result => console.log('User name is %s',result.rows[0].name));
|
||||
|
42
result.php
Normal file
42
result.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
use Casssandra;
|
||||
|
||||
$cluster = Cassandra::cluster()->build();
|
||||
$keyspace = 'glink';
|
||||
|
||||
$url = $_GET["url"];
|
||||
$shortlink = $_GET["glink"];
|
||||
|
||||
$session = $cluster->connect($keyspace);
|
||||
|
||||
//$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5');
|
||||
$rand_num = rand(0,99999999);
|
||||
|
||||
$values = array(
|
||||
'id' => $rand_num,
|
||||
'url' => $url,
|
||||
'shortlink' => $shortlink,
|
||||
);
|
||||
$statement = new Cassandra\SimpleStatement('INSERT INTO data (id, url, shortlink, when_created) VALUES (?,?,?,toTimestamp(now()))');
|
||||
$options = array('arguments' => $values);
|
||||
$result = $session->execute($statement,$options);
|
||||
|
||||
$statement = new Cassandra\SimpleStatement('SELECT url,shortlink FROM data WHERE id=?');
|
||||
$options = array('arguments' => array('id' => $rand_num));
|
||||
$result = $session->execute($statement,$options);
|
||||
|
||||
//$stringRepresentation= json_encode($result[0]);
|
||||
|
||||
//printf("%s\n\n\n",$stringRepresentation);
|
||||
|
||||
foreach($result as $row) {
|
||||
if (is_null($row)) {
|
||||
printf('Unsuccessful');
|
||||
} else {
|
||||
printf('Successful: The URL you entered was: %s and your GLink is: https://glink.zip/%s', $row['url'],$row['shortlink']);
|
||||
}
|
||||
}
|
||||
//printf('Done');
|
||||
|
||||
?>
|
Reference in New Issue
Block a user