This site uses cookies. By continuing, your consent is assumed. Learn more

109.1fm shares

Validating a registration form using javascript with php

HTML form validation can be...

By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. I'm developing a registration form for my site. Actually when a visitor choose an username, a php query to my MySQL DB is used to control if it's already used and if so, a javascript windowd appear. PHP is run on the server, Javascript is run on the client's machine. Once your PHP script has generated a page and sent it to the user, it doesn't run any longer.

Your client has no knowledge of a PHP script. It can't directly run, call, or read anything about your PHP script because it resides solely on the server never on the client's machine. Your client's machine does, however, know about your Javscript since it has been sent along with the page. No you can't do it like that. PHP is serverside, Javascript clientside. The moment Javascript is executed is the code working clientside.

All PHP code is fixed. It is fixed there as well. Same applies to PHP in Javascript. Here are some answers from related questions on stackoverflow: How to put php inside javascript?