Jump to content

I'd like someone to verify my code :)


Skewled

Recommended Posts

  • Replies 69
  • Created
  • Last Reply

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.

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;
}

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.

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.

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.

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.

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

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

}

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.