Basically my code declares a variable which checks to see if a specific string is entered into a textbox, when the user presses enter, then using substring, it declares a variable which contains a string after the specific word entered (shown below).
I would like to pass this variable to php and ultimately compare it against an SQL database or (but i've heard this is insecure/impossible) compare it directly against an SQL database from javascript.
Is this possible?
var match = textInput.value.indexOf("string");
if (keycode == 13 && match != -1) { <- checks to see if enter is pressed + "string" has been typed.
var some_string = text.input.value.substring(7); <- takes everything after the word "string"
and this is where I would like to pass the variable 'some_string' to the SQL database, to perform a check and return true or false.
I hope this is clear and thanks in advance for the help.
Use AJAX to pass the value to a PHP request handler that uses the value in the appropriate database call. For safety, escape the parameter with mysql_real_escape_string when building the SQL. Then have the handler return a response to indicate the outcome (JSON/XML/text/...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With