Hi I am facing a problem in my PHP query ,
Whenever I use query like written below works But and find one row in BD
$txtx = "nope";
$query = "SELECT * FROM `users` WHERE `uname`='Shabi RoxX' AND `pass`='$txtx'";
When I use to write "nope" like this
$txtx = "<script>document.write(String.fromCharCode(110,111,112,101));</script>";
$query = "SELECT * FROM `users` WHERE `uname`='Shabi RoxX' AND `pass`='$txtx'";
this query find 0 rows, however both prints/echo same string? whats wrong?
-
As far as I know, you can't just pass a javascript value directly to php, even if you're passing a string. The js code will be processed in the client side, not in the server side.luchosrock– luchosrock2012年12月27日 12:20:54 +00:00Commented Dec 27, 2012 at 12:20
3 Answers 3
You cannot write it like this --
Javascript is something that will execute at client side(browser) and PHP is a server side scripting language. And your are trying to execute JS in PHP...you cannot!
$txtx = "<script>document.write(String.fromCharCode(110,111,112,101));</script>";
4 Comments
users WHERE uname='Shabi RoxX' AND pass='nope'";What are you trying to accomplish here? What is the bigger problem you’re trying to solve?
The way it looks now, you want to check a password that's known in Javascript (on the client = the browser), using PHP (on the server).
While you can use PHP (on the server) to write Javascript which will be executed on the client, you can’t do it the other way round. To call server-side code from the client-side, you will have to make a POST or GET request, either by submitting a page, or (preferably) by making an AJAX call from Javascript.
Comments
use php's CHR function instead.
$txtx = chr(110).chr(111).chr(112).chr(101);
$query = "SELECT * FROM `users` WHERE `uname`='Shabi RoxX' AND `pass`='$txtx'";
I hope this helps. Thanks