Jump to content

Archived

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

Skewled

I'd like someone to verify my code :)

Recommended Posts

oh also, you're not actually calling the javascript anywhere.. so how do you envision that working?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

yeah but you have to physically call the checkUsername function from the form through an onClick or an onChange.

Share this post


Link to post
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;
}

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

once it's loaded, it's not checked again because you're not really looping it..  add that onclick into the submit button, and im sure it'll work for you..

Share this post


Link to post
Share on other sites

if it were working, when you put in an alert in the processUsername function or whatever its called..  that alert would have shown, but it didnt.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

yes but how does it display.. thats what i need to see.

Share this post


Link to post
Share on other sites

SELECT username FROM information WHERE username = 'testing'okay

 

I went back to my php script since they were both doing the same thing.

Share this post


Link to post
Share on other sites

okay....

 

have you tried running SELECT username FROM information WHERE username = 'testing' in phpmyadmin to see if it identifies a problem?

Share this post


Link to post
Share on other sites

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0002 sec )

 

that's the status from phpmyadmin

Share this post


Link to post
Share on other sites

okay and it's still not working...

 

lets try this...

 

after the mysqli_query line add:

 

$cnt = mysqli_num_rows($data);

echo 'the count is: '.$cnt;

 

and lets see what that is getting.

Share this post


Link to post
Share on other sites

if the username isn't taken:

 

the count is:0okay

 

if the username is taken:

 

denied

Share this post


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

Share this post


Link to post
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

Share this post


Link to post
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

}

Share this post


Link to post
Share on other sites

or...  we can get rid of everything but the last 4 letters of the result, and then check if it says 'okay'

Share this post


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

Share this post


Link to post
Share on other sites

I used a case to see what the response text would be and it still shows the entire first half of the page then it said okay at the bottom.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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