I have a code which is helping for determining which key is pressed. But I confused, I do not know how can I save this key -(button) is pressed-. Is this possible? Can I use php codes in javascript to create a new line in my mysql database?
<script type="text/javascript">
function textsizer(e) {
var evtobj = window.event ? event : e;
var unicode = evtobj.charCode? evtobj.charCode : evtobj.keyCode;
var actualkey = String.fromCharCode(unicode);
if (actualkey == "a") {
//database code needed
}
}
document.onkeypress = textsizer;
</script>
Your main problem is that JavaScript is a client-side language (it runs in the browser running on the user’s computer) and PHP is a server-side language (it runs on your web server). You can’t mix the two together because they run at different times.
What you could do is use is AJAX to send requests from your JavaScript code to your web server, without navigating away from the page, whenever a key is pressed. You’d simply send a key code (or the character that key code represents) as a parameter of the request, then your web server would handle saving that information to your database.