javascript - PHP Registration Form not processing AJAX data -


i may being stupid, trying process registration form using ajax call php page. php page working on it's own, when try post form data php page through ajax nothing happens.

this ajax call:

$(document).ready(function ($) {      $("#register").submit(function(event) {             event.preventdefault();                 $("#message").html('');                 var values = $(this).serialize();                     $.ajax({                     url: "http://cs11ke.icsnewmedia.net/dvprototype/external-data/register.php",                     type: "post",                     data: values,                     success: function (data) {                     $("#message").html(data);                     }                     });                 });   }); 

this form:

<div id="registerform">     <form method='post' id='register'>         <h3>register</h3>         <p>fill in chosen details below register account</p>         <p>username: <input type='text' name='username' value='' /><br />            password: <input type='password' name='password' ><br />            repeat password: <input type='password' name='repeatpassword'></p>            <input name='submit' type='submit'  value='register' >            <input name='reset' type='reset' value='reset'><br /><br />      </form>                  <div id="message"></div>                           </div> 

and php page:

<?php function clean_string($db_server = null, $string){         $string = trim($string);         $string = utf8_decode($string);         $string = str_replace("#", "&#35", $string);         $string = str_replace("%", "&#37", $string);         if (mysqli_real_escape_string($db_server, $string)) {             $string = mysqli_real_escape_string($db_server, $string);         }         if (get_magic_quotes_gpc()) {             $string = stripslashes($string);         }         return htmlentities($string);     }      function salt($string){         $salt1 = 'by*';         $salt2 = 'k/z';         $salted = md5("$salt1$string$salt2");         return $salted;     } ?>  <?php //form data                              $submit = trim($_post['submit']); $username = trim($_post['username']); $password = trim($_post['password']); $repeatpassword = trim($_post['repeatpassword']); // create variables $message = ''; $s_username = '';      //connect database 

{databaseconnection}

    $db_server = mysqli_connect($db_hostname, $db_username, $db_password);     $db_status = "connected";     if(!$db_server){          //error message         $message = "error: not connect database.";     }else{         $submit = clean_string($db_server, $_post['submit']);         $username = clean_string($db_server, $_post['username']);         $password = clean_string($db_server, $_post['password']);         $repeatpassword = clean_string($db_server, $_post['repeatpassword']);                  //check details entered                 if ($username&&$password&&$repeatpassword){                      //check password , repeat match                     if ($password==$repeatpassword){                          //check username correct length                         if (strlen($username)>25) {                             $message = "username long, please try again.";                                                    }else{                             if (strlen($password)>25||strlen($password)<6) {                                  //check password correct length                                 $message = "password must 6-25 characters long, please try again.";                                                           }else{                                 mysqli_select_db($db_server, $db_database);                                  // check whether username exists                                 $query="select username users username='$username'";                                 $result= mysqli_query($db_server, $query);                                 if ($row = mysqli_fetch_array($result)){                                     $message = "username exists. please try again.";                                 }else{                                      //insert password                                     $password = salt($password);                                     $query = "insert users (username, password) values ('$username', '$password')";                                     mysqli_query($db_server, $query) or die("registration failed. ".                                      mysqli_error($db_server));                                     $message = "registration successful!";                                 }                             }                         }                     }else{                         $message = "both password fields must match, please try again.";                     }                 }else{                     $message = "you must fill in fields, please try again.";                     }             }     echo $message;           mysqli_close($db_server);  ?> 

apologies code. feel may making stupid mistake don't know why data isn't being posted or returned.

thanks in advance!

notice: more comment answer more readable since includes code.

== edit ==

i checked code on http://cs11ke.icsnewmedia.net/dvprototype/#registerlogin, form doesn't have id assigned it

first: use console...do see xmlhttprequest in console? responses/headers etc? can't stress enough: use console , report here!!!

next overly complicated ajax call...dumb down to:

$('#register').submit(function(){     $('#message').html('');      $.post("http://cs11ke.icsnewmedia.net/dvprototype/external-data/register.php",         $(this).serialize(),         function(response){             console.log(response);             $('#message').html(response);         }     );      return false; }); 

in php put on top check whether @ came through:

die(json_encode($_post)); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -