Click here to Skip to main content
14,640,678 members
Rate this:
Please Sign up or sign in to vote.
I am trying to get values from javascript and stored into MySQL database. and reterive the values based on the output values from database.

So I need to know How to store the javascript values in MySQL database?

What I have tried:

can anyone help me.
Js:
var age = new Date().getFullYear()-getYearInteger();

in php page :
$sql="INSERT INTO expression (id, age) VALUES ('','$age')";

but it is stored value 0 in mysql database. how to call function in ajax and store the values in database
Posted
Updated 26-Nov-16 19:42pm
Comments
Mohtshm Zubair 26-Nov-16 9:54am
   
plz paste full code here

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

That happened when you insert string value ('$age') into number field (age) in MySQL.
Furthermore, DO NOT concatenate variables directly into an SQL statement, that is vulnerable to SQL Injection[^].
Use PHP Prepared Statements[^] instead.
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100