Jump to content

I'd like someone to verify my code :)


Skewled

Recommended Posts

  • Replies 69
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Sorry didn't include that

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>User Registration</title>
<script src="scripts/utils.js" type ="text/javascript"></script>
<script src="scripts/validation.js" type="text/javascript"></script>
</head>
<body>

 

this is all at the very top of my php file, also changed the input field and same results.

Link to comment
Share on other sites

Isn't that achieved here?

 

function initPage() {
  // Tell the browser what element we need to work with and what function to call
  document.getElementById("username").onblur = checkUsername;
  document.getElementById("register").disabled = true;
}

Link to comment
Share on other sites

yeah but that function is only called once @ page load.... 

 

so if you do this:

 

<input id="register" type="submit" value="Sign Up" name="register" class="signsub" onClick="checkUsername();"/> it should work.

Link to comment
Share on other sites

It's called at page loading and works to check the username when you leave that input field. The alerts are verifying the information changing when I type new usernames.

 

It's just all the usernames come back as denied even when I know it's a good name that isn't registered.

Link to comment
Share on other sites

I'm sorry I edited the post where the alerts came back ok, I failed to let you know that.

 

I placed all of the alerts and it steps through the program, and they all work.

 

But for some reason it won't register any name as new, so it will deny all names.

 

That's why I originally believed the issue was with my php script that checks for the username in the database.

Link to comment
Share on other sites

okay, so the many times i asked you to echo $query, what was the result of that?

 

since thats where the ball is being dropped apparently.

 

it should pring out something like SELECT COUNT(*) FROM information WHERE username = 'ucntkilme'

 

if it's working correctly.. 

 

if that's not working, take the escape out of the javascript function and try it then.

 

also take that result from the echo, and try it in phpmyadmin.

Link to comment
Share on other sites

and if you alert(request.responseText); in the showUsernameStatus function (right after: if(request.status == 400) { and before the if statement for 'okay' does it show anything?

 

i'll be awol for about an hour, im getting off work right now -- i'll check in when i get home.

Link to comment
Share on other sites

It sends the following alert

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

 

        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

 

<title>User Registration</title>

 

<link type="text/css" rel="stylesheet" href="tlstyle.css" />

 

<script src="scripts/utils.js" type ="text/javascript"></script>

 

<script src="scripts/validation.js" type="text/javascript"></script>

 

</head>

 

<body>

 

the count is:0okay

Link to comment
Share on other sites

ahh thats where the issue is..  you should have the response be nothing but 'okay' and to achieve that, you either use cases, or use some if statements..  such as: if ($_REQUEST['username'] == '') { // show the form } else { // ajax processing}

 

or:

 

$a = isset($_REQUEST['a'])? $_REQUEST['a'] : '';

switch ($a) {

default:

// show the form

break;

 

case submit:

// ajax handling

break

}

Link to comment
Share on other sites

Had some company stop by, I've never used a case before so I need to look into using that. I'll try to work with refining the if statements I have so far to see if I can get it to work out.

 

It was saying the count is:0okay because I was echo'ing the query still

 

I'll post back here either later or tomorrow, thanks again!

 

Edit: I removed the query echo and either get okay or denied when I access the php script directly.

 

The alerts are all running fine until It gets to the showUsernameStatus, it's like the ajax script isn't getting the value correct for okay or denied.

Link to comment
Share on other sites

let me do some fiddling around, worst case scenario we'll have to change the target words to something unusual for the script to find.  just in case someone puts an input of 'okay' somewhere.

 

perhaps okay md5 would work. on that..  let me get you the code to alter in both php and javascript.

Link to comment
Share on other sites

in php:

 

$ok = md5("okay");

$den = md5("denied");

 

echo $ok;

return $ok;

 

echo $den;

return $den;

 

in javascript:

 

var hashed = hexMD5('okay');

var response = request.responseText;

if(response.search(hashed) != -1) {

// do the good thing here

} else {

// do the bad thing here

}

 

perhaps that'll work.

Link to comment
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.