2

using jquery ajax i have a text field where a name is entered how can i have it where when a user enters a name ajax checks to see if the name already exists in the db and if it does a message is displayed that this name already exists and the form cannot be submitted until a name is entered that does not exist?

this would be the php

<?php
$name = $security->secure($_POST['name']) //security->secure() cleans the field
$query = $db->query("select name from table where name = '$name'");
if($db->num_rows($query) != 0) { "that record already exists"; }
//disable the form button until a name is entered that does not exist.
?>
1
  • i found a good explanation thnx: vimeo.com/4173282 Commented Dec 7, 2010 at 23:55

2 Answers 2

2

in Jquery you can use the method $.ajax, $.post , and even $.get to make an easy ajax call example:

$(document).ready(function(){
  $.ajax({
     type: 'POST', /*the method u are using*/
     url: url, /* http://yourdomain.com/post.php */
     success: function(data){alert('Name exists')} /* What to do in case of success */
  });
}); 

I hope this was helpful enough to do the job for u .

Sign up to request clarification or add additional context in comments.

Comments

1

@sammen

you need to use jquery ajax

http://api.jquery.com/jQuery.ajax/

send the user name to the backend , and execute your php and send a status to the UI.

on the success handler of ajax , you can call a method or show a error that name is not valid

you can use jquery ajax for this

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.