I'm starting to learn some of SQL with javascript and i want to put my variable ("Val_Points from javascript") into a table ("Usuarios") of a user (ex : Robert). It's this posible via Javascript or there are some other methods ?
var Val_Points = 0; /* Variable */
$('.btn').click(function() {
Val_Points += 5; /* value +5 */
/* Update individual SQL Data
var UpdateSQL = dbConn.executeUpdate('UPDATE Usuarios SET Points="$Val_Points" WHERE Username="$_SESSION[username]"');
*/
$('#exp_bar').val(Val_Points);
});
<?php
session_start();
require 'connect.php';
$username_session = $_SESSION['username']; /* "Robert" Session */
$query = "SELECT * FROM `Usuarios` WHERE usuario='$username_session'";
$result = mysqli_query($connection, $query);
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Points</p>
<progress id ="exp_bar" value="0" max="100"></progress><br>
<button class="btn">+1</button>
Also i was seeing a script that simplifly this https://hiddentao.github.io/squel/ Maybe could be more readable in scripting with this. Any help?
EDIT
I tried to do all of this with php via $_SESSION
<?php
session_start();
require 'connect.php';
$username_session = $_SESSION['username'];
$query = "SELECT * FROM `Usuarios` WHERE username='$username_session'";
$result = mysqli_query($connection, $query);
if(empty($_SESSION['Val_Points'])){
$Val_Points_Session = $_SESSION['Val_Points'] = 0;
}
echo "<form action='' method='POST'>
<progress id ='exp_bar' value='".$_SESSION['Val_Points']++."' max='100'></progress>
<input class='btn' type='submit' value='Increase val' />
</form>";
echo $_SESSION['Val_Points']; /* Show current variable */
$Update_SQL = "UPDATE Usuarios SET Points='$Val_Points_Session' WHERE username='$username_session'";
?>
But it doesn't update the table, the table keeps with the same value
Username Points
Robert 0
</div>