Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
1.00/5 (1 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.
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
Updated 26-Nov-16 19:42pm
Mohtshm Zubair 26-Nov-16 9:54am    
plz paste full code here

1 solution

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.
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900