Jump to content

JS Code not working at all


graham23s

Recommended Posts

Hi GUys,

 

on my desk top i knocked up a few example of form validation with a basic username/password field, it worked great, then i implemented it into my site but it looks like the javascript code is getting through somehow

 

login.php:

 

<?php
     // the includes //
     include("includes/db_connection.php");
     include("includes/constants.php");
     include("includes/functions.php");
     include("includes/header.php");
     include("includes/nav0.php");
     include("includes/referer.php");
?>
<?php
#################################################
# login.php
#################################################
if(isset($_POST['submit'])) {

  // The all important post variables //
  $var_username = mysql_real_escape_string(trim($_POST['username']));
  $var_password = mysql_real_escape_string(trim($_POST['password']));
  
  // initialize errors array //
  $errors = array();
  
  // blank submission //
  if(empty($var_username) || empty($var_password)) { 
   $errors[] = ("You never filled in both login fields!");
  }
  
  // get some details from mysql on the user //
  $q = "SELECT `id`,`username`,`password` FROM `users` WHERE `username`='$var_username' AND `password`='$var_password' LIMIT 1";
  $r = mysql_query($q);
  $row = mysql_fetch_array($r);
  
  // this contains either 1 or 0 //
  $any_results = mysql_num_rows($r);
  
  if($any_results != 1) {  
   $errors[] = ("Sorry, that username & password combination isn't in our database, please check it again!");     	     
  } else {
  
  // no errors in the array //
  if(empty($errors)) {
   
  // update the login timer //
  $var_update_time_query = mysql_query("UPDATE `users` SET `lastlogin` = now() WHERE `username`='$var_username' AND `password`='$var_password'");

  // There was a result back //
  session_start(); 
  
  $_SESSION['id'] = $row['id'];
  $_SESSION['username'] = $row['username'];
  $_SESSION['loggedin'] = 'yes'; 
  
  // redirect to members page //
  header("Location:myaccount.php"); 
  ob_clean();  
  
   }
   
  } // end if empty errors // 
  
  } // end the isset //
  
  echo ("<table width=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FF0000\">\n");
  echo ("<tr>\n");
  echo ("<td valign=\"top\">\n");
  echo ("<form action=\"login.php\" name=\"loginform\" method=\"POST\" onSubmit=\"logincheck()\">");
  echo ("<table class=\"tablesmain\" align=\"left\" width=\"300\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n");
  echo ("<tr>\n");
  echo ("<td class=\"header_boxes\" colspan=\"2\" align=\"left\"><span class=\"header_txt\">Members Login</span></td>\n");
  echo ("</tr>\n");
  echo ("<tr>\n");
  echo ("<td align=\"right\"><b>Username:</b></td><td align=\"left\"><input type=\"text\" name=\"username\" value=\"\"></td>\n");
  echo ("</tr>\n");
  echo ("<tr>\n");
  echo ("<td align=\"right\"><b>Password:</b></td><td align=\"left\"><input type=\"password\" name=\"password\" value=\"\"></td>\n");
  echo ("</tr>\n");
  echo ("<tr>\n");
  echo ("<td colspan=\"2\" align=\"right\">[<a class=\"foot_links\" href=\"recoverpassword.php\">FORGOT PASSWORD</a>]  <input type=\"submit\" name=\"submit\" value=\"Login\"></td>\n");
  echo ("</tr>\n");
  echo ("</table></form>\n");
  echo ("</td>\n");
  echo ("<td valign=\"top\" align=\"left\">\n");
  echo ("<h1>Why Join My Live Audition?</h1>\n");
  echo ("<ul>\n");
  echo ("<li>Search performers by location</li>\n");
  echo ("<li>Send unlimited messages</li>\n");
  echo ("<li>Leave comments on performers profiles</li>\n");
  echo ("<li>Rate your fellow members</li>\n");
  echo ("<li>Write your own blog</li>\n");
  echo ("<li><b>Plus MUCH more join today!</b></li>\n");
  echo ("<li><a class=\"foot_links\" href=\"signup.php\">Not a member yet? sign up here!</a></li>\n");
  echo ("</ul>\n");
  echo ("<img src=\"images/placeholder.jpg\">\n");
  echo ("</td>\n");
  echo ("</tr>\n");
  echo ("</table>\n");
  
  // display the errors if there was any //
  if(!empty($errors)) {
  
  foreach($errors as $errormessage) 
  {
    echo ('<div id="loginerror">'.$errormessage.'</div><br />');
  }

  }
?>
<?php
     // include the footer //
     include("includes/quantcast.php");
     include("includes/footer.php");
?>

 

i did the onSubmit part and my function:

 

// this function check all boxes in the inbox //
function CheckAll()
{
count = document.inboxform.elements.length;
    for (i=0; i < count; i++) 
{
    if(document.inboxform.elements[i].checked == 1)
    }
       document.inboxform.elements[i].checked = 0;       
    } else {   
       document.inboxform.elements[i].checked = 1;
    }
  }
}

// this function un-checks all boxes in the inbox //
function UncheckAll()
{
count = document.inboxform.elements.length;
    for (i=0; i < count; i++) 
{
    if(document.inboxform.elements[i].checked == 1)
    {
       document.inboxform.elements[i].checked = 0;       
    } else {    
       document.inboxform.elements[i].checked = 1;      
    }
  }
}

// this function checks that the login details were filled in //
function logincheck()
{
  if(document.loginform.username.value == "")
  {
  alert("You never filled in the username.");
  }
  
  // none false so return true //
  return true;
}

 

i think i have named all the forms correctly i have no idea what to check, is there any type of trouble shooting i could to test the js is gettting through at all?

 

thanks guys

 

Graham

 

Link to comment
https://forums.phpfreaks.com/topic/88778-js-code-not-working-at-all/
Share on other sites

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.