Monday, 15 April 2013

reference a php string in jquery? -


I am using the following code to generate a random string in php, and then in my database like this Archiving:

  & lt ;? Php $ allowance_promo = substit (str_shuffle ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 8); ? & Gt;  

Then I am using my query to store this value in the database:

  $ query = sprintf ("UPDATE internal_users SET allowance_promo = '$ Allowance_promo' WHERE user_id = '{$ _ session [' id ']}' "); $ Result = mysql_query ($ query);  

Then I am using another query to get the value:

  $ query2 = sprintf ("select SELECT * FROM internal_users WHERE user_id" = '{$ _ Session [id']} '"); $ Result2 = mysql_query ($ query2); While ($ line = mysql_fetch_array ($ result2)) {$ check = $ line ['allowance_promo'];  

So I'm trying to use jquery to check if the value entered in my input field matches the database like this:

  & lt; Script & gt; Click (function () {var discountCode = "& lt ;? Php echo $ check;?";; Var codeEntered = $ ("input [name = 'promo']"). Val (); if (discountCode == codeEntered) Remove {$ ('# submit') Remove ("disabled");}}}}};  

Although I have a php string There is a lot of difficulty in using the work. If I use normal text like var discount code = '123' then it works, but when I try and var discountCode = "& Lt; php echo $ check ;? & gt; "; does this work wont do anybody Thank you,

Change your script to the script below. Click discountCode outside the event handler and delete $ (document) .ready ();