ebolt007 Posted November 23, 2011 Share Posted November 23, 2011 Ok, so I am new to Ajax and am making a forma that will check the user etc. Seems easy, but wow, I'm just lost with all the different things I'm reading, but I know exactly what I want and can easily do it in PHP but of course that is slower and reloads the page. But I am trying to really secure my page so I am stripping everything before it gets to anywhere on my site, even the ajax. So this is what I am doing. My form on index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script src="js/runonload.js"></script> <script type="text/javascript" src="js/checkcreateuser.js"></script> <link href="css/check.css" media="all" type="text/css" rel="stylesheet"> </head> <body id="mysite"> <form method="post" id="registerForm" name="create_form" action="index.php"> <input type="hidden" name="action" value="create" /> <table width="290px"> <tr> <td align="right"> User Name: </td><td> <input name="usernamecreate" id="usernamecreate" class="sign_up_input_area" type=text value=""> </td> </tr><tr> <td align="right"> Password: </td><td> <input name="passwordcreate" id="passwordcreate" class="sign_up_input_area" type=password value=""> </td> </tr> </table> <input type="submit" class="submitButton2" name="Login" value="Create Account"> <div id="error_log"> <label class="error" for="usernamecreate" id="username_error">Username is required.</label> <label class="error" for="usernamecreate" id="username_error2">Username is already in use.</label> <label class="error" for="passwordcreate" id="password_error">Password is required.</label> </div> Then I want my javascript to work, which does work right now, but only for empty values. I want to be able to compare if the user is in the database and for other PHP functions. Like Would I put this in a seperate checkcreate.php file? $usernamemain1 = trim($_POST['username']); $usernamemain = stripslashes(strip_tags($usernamemain1)); $usernamecheck = mssql_real_escape_string($usernamemain, $link); $username_lower = strtolower($usernamecheck); $sql = "SELECT LoweredUserName FROM Users where LoweredUserName = '$username_lower'"; $sql_result = mssql_query($sql); $login_row = mssql_fetch_assoc($sql_result); $username = $login_row['LoweredUserName']; $passwordmain1 = trim($_POST['password']); $passwordmain = stripslashes(strip_tags($passwordmain1)); $passwordcheck = mssql_real_escape_string($passwordmain, $link); so I want to be able to use thos evariables in my checkcreateuser.js which is settup like $(function() { $('.error').hide(); $('input.sign_up_input_area').css({backgroundColor:"#FFFFFF"}); $('input.sign_up_input_area').focus(function(){ $(this).css({backgroundColor:"#FFDDAA"}); }); $('input.sign_up_input_area').blur(function(){ $(this).css({backgroundColor:"#FFFFFF"}); }); $(".submitButton2").click(function() { // validate and process form // first hide any error messages $('.error').hide(); var username = $("input#usernamecreate").val(); if (username == "") { $("label#username_error").show(); $("input#usernamecreate").focus(); return false; } if (<?echo $username_lower?> == "<?echo $username?>") { $("label#username_error2").show(); $("input#usernamecreate").focus(); return false; } var password = $("input#passwordcreate").val(); if (password == "") { $("label#password_error").show(); $("input#passwordcreate").focus(); return false; } var dataString = 'username='+ username + '&password=' + password; //alert (dataString);return false; $.ajax({ type: "POST", url: "", data: dataString, success: function() { $('#contact_form').html("<div id='message'></div>"); $('#message').html("<h2>Form Submitted!</h2>") .hide() .fadeIn(1500, function() { $('#message').append("<img id='checkmark' src='images/check.png' />"); }); } }); return false; }); }); runOnLoad(function(){ $("input#username").select().focus(); }); I can't get the if (<?echo $username_lower?> == "<?echo $username?>") to use variables, of course they aren't seeing any of the variables because I don't know if I put this into a different file, then point my form action to that file and the ajax then sees it run or what? I'm really confused on it all, if anyone can help out that would be great. All the tutorials I keep finding are the same things over and over and don't really help because they always leave out various parts they are using or doing. I understand this much so far tho, but how do I do the variables in ajax when it posts type thing? Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/251696-php-inside-my-ajax/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.