Jump to content

Recommended Posts

I've been lookin at and reading various tutorials on Ajax for the past few weeks, and still have no idea where to start, every tutorial I read is from around 2007 and everyone seems to contradict itself, or not show any usage based on integrating PHP, I want to make a form that checks if the user is used in a database and make sure the field isn't empty etc. All the forms I find just have simple actions without any real PHP integration involved, and everything I read keeps saying, make sure it's secure, and the comments say that the form code is subject to hijacking. Does anyone know of a great tutorial to use for createing a user and submitting this user to a database and checking to see if the user is valid otherwise give an error message? I mean something basic like,

 

<form method="post" id="createForm" action="">
<table width="290px">
                  <tr>
                  <td align="right">
                  User Name:
                  </td><td>
                  <input name="username" id="username" class="sign_up_input_area" type=text value=""> 
                  </td>
                  </tr>
</table>
<input type="submit" class="submitButton" name="submit" id="submit" value="Create Account">
</form>
<div id="error">
    <ul>
      <li><? echo $errors; ?></li>
</ul>
</div>

 

Then when the button is selected it would run thru various php functions like

 

    $usernamemain1 = trim($_POST['username']);   
    $usernamemain = stripslashes(strip_tags($usernamemain1));
    $usernamecheck = mssql_real_escape_string($usernamemain, $link);
    $username_lower = strtolower($usernamecheck);

if (preg_match("/^[0-9a-zA-Z_]{3,}$/", $usernamecheck) === 0)
{
	$errors[] = '*User must be larger than 5 chars and contain only digits, letters and underscore'; 
}
    $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']; 

  if ($username == $username_lower)
{
	$errors[] = '*Username is already in use, please choose a new one.';
}

     if(is_array($errors))
{
	echo '<p class="error"><b>The following errors occured</b></p>';
	while (list($key,$value) = each($errors))
	{ 

		echo '<span class="error">'.$value.'</span><br />';
	} 
}

 

 

Or something like that, is that secure? How do I do the Ajax then?

Thanks

Link to comment
https://forums.phpfreaks.com/topic/253574-where-to-start/
Share on other sites

You might want to have a read of this: http://www.phpfreaks.com/forums/index.php?topic=323280.0

 

that is a good read, and very true. Jquery or something of the sorts is imo the way to go when attempting to learn ajax. It is compact, easy to learn/use, and will save the coder a good amount of time.

 

jquery.com has everything that you will need, including downloads, documentation, etc. to get you started and on your way to learning jquery.

Jquery's ajax api is very easy to learn for really any level of coder.

 

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

Link to comment
https://forums.phpfreaks.com/topic/253574-where-to-start/#findComment-1300063
Share on other sites

Awesome! Thanks both of you, I didn't realize JQuery was basically a framework to simplify and make my life easier, and have been trying to write everything from scratch basically since everything I have been reading has just basically contradicted itself. I really appreciate being pointed in the right direction. :) Happy Coding!

Link to comment
https://forums.phpfreaks.com/topic/253574-where-to-start/#findComment-1300119
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.