I am trying to create a live email availability using Ajax. I want to assume input and send it to php where it will be checked that it is in the database but i can not make it. When I test the scripts with firebug, there is a reaction, but the output is always the same thing as if the email exists or not. It always shows me that it is not existing.
The table is called the company Email field for email is the field email.
The connection to the database is fine. I think the problem is in my Ajax code because it is always giving me "the output".
This is my php code:
& lt ;? Php // This is a sample code if you want to check the username from mysql db table (isset ($ _ POST ['email'])) {$ email = $ _POST ['email']; $ DbHost = 'localhost'; // Generally localhost $ dbUsername = 'root'; $ DbPassword = 'password'; $ DbDatabase = 'php_test'; $ Db = mysql_connect ($ dbHost, $ dbU name, $ dbPassword) or die ("Unable to connect to database server."); Mysql_select_db ($ dbDatabase, $ db) or die ("Could not select database."); $ Result = mysql_query ("Select email from company where email = '". $ Email ""' ") or die (mysql_error ()); If (mysql_num_rows ($ result)) {echo 'not ok'; } Else {echo 'OK'; }}? & Gt; This is AJAX code
$ (document) .ready (function () {$ ("# email"). Blur (function () { $ .ajax ({type: "POST", url: "unique_check.php", data: {email: $ ("# email") .val ()}, datatype: "json", success: function (msg) { If (msg == "OK") {Warning ("Free")} Other {Warning ("Tech")}}});});}); Please tell me where my fault is or if there is a better way, then give it to me. Keep in mind that I am new to AJAX and PHP. Thanks a lot!
I think you want:
if ($ Results! = False & amp; amp; mysql_num_rows ($ result) & gt; {} 'echo'; } Else {echo 'OK'; } If this does not work, make sure that you want what you want.
No comments:
Post a Comment