I'm working on a registry system with PHP/XML, and I just honestly can't figure this out.
I have it when you submit the info you do checkUser which goes to the php side, should check if the username submitted is in the XML file and if the password is blank. And if it returns "Available" to do function sendInfoOut and if it returns anything else its supposed to bring up an alert box, but just nothing happens.
But so far it's unresponsive and I just can't find out the problem...
If I input Kyle Palmer for the username and password it should say "username already taken".
HTML code
PHP codeCode:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title>Chatroom</title> <style type="text/css"> /* all predefined styles go here */ </style> </head> <body> <div id="responseDiv" style="position: absolute; top: 000px; left: 100px;"> </div> <div id="Registration" style="position: absolute; top: 100px; left: 500px;"> username: <input type="text" id="userText" size="25" onkeydown = "if(event.keyCode == 13) checkUser(document.getElementById('userText').value, document.getElementById('passText').value)"> <br> password: <input type="text" id="passText" size="25" onkeydown = "if(event.keyCode == 13) checkUser(document.getElementById('userText').value, document.getElementById('passText').value)"> <br> <input type="button" value="Submit" onclick="checkUser(document.getElementById('userText').value, document.getElementById('passText').value)"> </div> <script type="text/javascript"> var submitGopher = new XMLHttpRequest(); var checkGopher = new XMLHttpRequest(); var myTimer = null; function timer() { myTimer = setInterval("gopherDoorPause()", 3000 ); } function gopherDoorPause() { clearInterval(myTimer); window.location = receivedInfo[1]; } function sendInfoOut(user2, pass2) { urlAddress = "Register.php?op=sendInfo&username=" + user2 + "&password=" + pass2; submitGopher.open("GET", urlAddress, true); submitGopher.onreadystatechange = sendInfoDoor; submitGopher.send(null); } function sendInfoDoor() { if(submitGopher.readyState == 4) { if(submitGopher.status == 200) { receivedInfo = submitGopher.responseText.split('%'); document.getElementById("responseDiv").innerHTML = "<a style='color:red;'>" + receivedInfo[0] + "</a><br>"; if(receivedInfo[0] == "Account Created.") { timer(); } } } } function checkUser(user, pass) { urlAddress = "Register.php?op=checkUser&user=" + user + "&pass=" + pass;" // create the url address to send out checkGopher.open("GET", urlAddress, true); checkGopher.onreadystatechange = checkUserDoor; checkGopher.send(null); } function checkUserDoor() { if(checkGopher.readyState == 4) { if(checkGopher.status == 200) { checkInfo = checkGopher.responseText.split('%'); document.getElementById("responseDiv").innerHTML = "<a style='color:red;'>" + checkInfo[0] + "</a><br>"; if(checkInfo[0] == "Available") { sendInfoOut(document.getElementById("userText").value, document.getElementById("passText").value) } else { alert(checkInfo[1]); } } } } </script> </body> </html>
XML codeCode:<?php $operation = $_GET["op"]; $xmlFile = simplexml_load_file("AccountInfo.xml"); $xmlLocalCopy = new SimpleXMLElement($xmlFile->asXML()); if($operation == "sendInfo") { $username = $_GET["username"]; $password = $_GET["password"]; $newAcct = $xmlLocalCopy->addChild("Accounts"); $newAcct->addChild("username", $username); $newAcct->addChild("password", $password); $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xmlLocalCopy->asXML()); $dom->save("AccountInfo.xml"); echo "Account Created.%login.html"; } else if($operation == "checkUser") { $user = $_GET["user"]; $pass = $_GET["pass"]; foreach ($xmlLocalCopy as $Accounts) { $name = $Accounts->username; if($user == $name) { echo "Invalid%Username already taken."; } else if($pass == "") { echo "Blank%Please enter a password."; } echo "Available%Username available"; } } ?>
Code:<?xml version="1.0"?> <AccountInfo> <Accounts> <username>Kyle</username> <password>Palmer</password> </Accounts> </AccountInfo>
Please help![]()




Reply With Quote