|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
Join Date: Sep 2004
Posts: 109
|
JS Problem
I am writing a web application which is based around a simple command system that I want to manipualte with JS. Index.php loads up the common.php file containing this code for commands:
*?- Command System --> *form action="index.php" method="post" id="form"> *input type="hidden" name="act" id="act" value=""> *input type="hidden" name="id" id="id" value=""> */form> *script type="javascript"> var Fact=document.getElementById("act"); var Fid=document.getElementById("id"); var form=document.getElementById("form"); function actID(action,id) { Fact=action; Fid=id; form.submit(); } function actx(action) { Fact=action; form.submit(); } */script> Index.php then includes the appropriate sub-page, eg. login.html. I replaced all occurences of < with *. *html> *body> *form action="javascript:actx('login');" method="post"> *table> *tr> *td> Username:*/td> *td> *input type="text" name="user" />*/td> */tr> *tr> *td> Password:*/td> *td> *input type="password" name="pass" />*/td> */tr> *tr> *td> *input type="submit" value="Login" />*/td> *td> *a href="javascript:actx('signup');">Register*/a>*/td> */tr> */table> */form> */body> */html> That is my login page. Thus, the full page would look like this when everything is added together. *?- Command System --> *form action="index.php" method="post" id="form"> *input type="hidden" name="act" id="act" value=""> *input type="hidden" name="id" id="id" value=""> */form> *script type="javascript"> var Fact=document.getElementById("act"); var Fid=document.getElementById("id"); var form=document.getElementById("form"); function actID(action,id) { Fact=action; Fid=id; form.submit(); } function actx(action) { Fact=action; form.submit(); } */script> *center>*div style='font-size:36pt;'>Test RPG*/div>*br>*div style='font-size:14pt;'>RPStatus Version 1.1.1*/div>*/center>*br>*br>*html> *body> *form action="javascript:actx('login');" method="post"> *table> *tr> *td> Username:*/td> *td> *input type="text" name="user" />*/td> */tr> *tr> *td> Password:*/td> *td> *input type="password" name="pass" />*/td> */tr> *tr> *td> *input type="submit" value="Login" />*/td> *td> *a href="javascript:actx('signup');">Register*/a>*/td> */tr> */table> */form> */body> */html> However, this code gives me the error: Error: actx is not defined Source File: javascript:actx('signup'); Line: 1 Can someone please tell me what is wrong with my code? Last edited by Kulag; 01-06-2006 at 06:11 PM. |
|
|
|
|
|
#2 |
|
Member (9 bit)
Join Date: Jan 2006
Posts: 343
|
If this is code, verbatim, try closing your form tags and placing the forms inside of your tables. in your anchor *a href="javascript:actx('signup');">, do this:
* ahref="javascript://" onClick="javascript:actx('signup');">. Let me know how it goes. Last edited by DynamicTech; 01-06-2006 at 08:09 PM. |
|
|
|
|
|
#3 |
|
Member (7 bit)
Join Date: Sep 2004
Posts: 109
|
The form tags are closed. I have the forms outside the tables because that's what VWD 8 told me to do. (Visual Web Developer) I'll try the other stuff tommorow morning. Bedtime!
|
|
|
|
|
|
#5 |
|
Member (9 bit)
Join Date: Jan 2006
Posts: 343
|
I got your code, and am checking it out. Give me a little while to toy with it.
|
|
|
|
|
|
#6 |
|
Member (9 bit)
Join Date: Jan 2006
Posts: 343
|
Kulag, what are hoping to accomplish? Are you trying to place the value login or signup into the act value? I am assuming you are wanting your index.php
page to perform two different functions depending on whether the user wants to sign in or register. Let me do a rewrite and see what you think. |
|
|
|
|
|
#7 |
|
Member (9 bit)
Join Date: Jan 2006
Posts: 343
|
I have three different solutions to your problem, as I understand it. I could not get the javascript to function properly. I messed around with almost two hours
. Check them out here: http://www.dynamicit.us/test.htm.They will be up till 3 pm. The third form involves some javascript, the rest are straight up form submissions via the post method. Let me know if I can help you any further. |
|
|
|
|
|
#8 |
|
Member (7 bit)
Join Date: Sep 2004
Posts: 109
|
Nevermind, removed the type="javascript" property from the script tag and it works perfectly. Wierd...
|
|
|
|
|
|
#9 |
|
Member (7 bit)
Join Date: Sep 2004
Posts: 109
|
Well, all is working fine except my login script:
$result=mysql_query("select * from `members` where 'name' = '".$user."' and 'password' = '".$pass."'") or Bugnet(); if (mysql_num_rows($result)<1) { Login_Fail(); } $row=mysql_get_rows($result); $_SESSION[$rp_id_cookie]=$row['id']; $_SESSION[$rp_user_cookie]=$row['user']; $_SESSION[$rp_auth_cookie]=$row['permissions']; What is wrong with this code? Every time I run it, despite the fact that the username and password are identical to those stored in the database, it calls Login_Fail. I checked it, and no rows are being returned by MySQL. Also, I get no PHP, javascript, or MySQL errors. |
|
|
|
|
|
#10 |
|
Member (9 bit)
Join Date: Jan 2006
Posts: 343
|
Ok, let me edit this post. Your problem is within your mysql sytax. name and password should be literal. So your mysql sytax should look like this:
$result=mysql_query("select * from members where name = '".$user."' and password = '".$pass."'") or Bugnet(); I always write mine like this: $result=mysql_query("SELECT * FROM members WHERE name = '$user' AND password = '$pass'") or Bugnet(); The way you have it now, mysql is reading name and password as variables and not row names. Maybe this will help. Last edited by DynamicTech; 01-08-2006 at 08:38 AM. |
|
|
|
|
|
#11 |
|
Member (7 bit)
Join Date: Sep 2004
Posts: 109
|
What I have is a table with 4 columns (name, password, email, and permissions) each user is stored on a seperate row, so the query used, whit the correct username and password, should return one row, containing the data for that user. However, MySQL isn't returning ANY rows, so (mysql_num_rows($result)<1) is triggering, along with Login_Fail(). Basically, Login_Fail excecutes die("Error, no such user/password.").
I do see what you mean about the mysql_get_rows() function. |
|
|
|
|
|
#12 |
|
Member (9 bit)
Join Date: Jan 2006
Posts: 343
|
I edited my last post. This one should be more relevant to your problem.
Let me know how it goes. |
|
|
|
|
|
#13 |
|
Member (7 bit)
Join Date: Sep 2004
Posts: 109
|
Ah, yes that works, I wonder why though, since that kind of code has always worked in the past for me... Anyways, I ran up against another odd bug, where PHP is telling me that a variable that I put in the config file (included) is not defined. I can echo the variable, and it's used in other locations without a problem. Success: if (isset($_SESSION[$rp_auth_cookie])) {$loggedin=1;} else { $_SESSION[$rp_auth_cookie]=""; $loggedin=0;} if ($_SESSION[$rp_auth_cookie]<1) { SignIn(); } That's my authorisation code. However, the login code fails: $result=mysql_query("select * from members where name = '$user' and password = '$pass'"); if (mysql_num_rows($result)<1) { Login_Fail(); } $row=mysql_fetch_array($result); $_SESSION[$rp_id_cookie]=$row['id']; $_SESSION[$rp_user_cookie]=$row['name']; $_SESSION[$rp_auth_cookie]=$row['permissions']; It fails at the lines where it starts with $_SESSION. The following code also fails with the same error. function Footer() { if ($loggedin=1) { ?> *br>*br>You are currently logged in as *?php echo $_SESSION[$rp_user_cookie];?>.*br> Options: *a href="javascript:actID('edit-email',*?php echo $_SESSION[$rp_id_cookie];?>);">Change E-Mail Address*/a> *a href="javascript:actx('logout');">Logout*/a> *?php if ($_SESSION[$rp_auth_cookie]=3) {?> *a href="admin.php">Admin Control Panel*/a> *?php } } die(" |