I'm new to PHP/Javascript. I have a simple form I want to validate the
fields with javascript and then run the PHP script. All the scripts
are in one page. I want PHP to control where the next page is. It
works fine without the javascript but when I add the javascript the
page doesn't do anything besides the validation. Thanks for your
help... Chong
----login.html--------------------------------
<?php
ob_start();
session_start() ;
require('dataso urce.html');
switch ($_POST['process'])
{
case 'Login':
$_SESSION['login'] = $_POST['login'];
$sql = "SELECT first_name, last_name, security_access , expire,
passwd_date FROM sy_user WHERE login = '".$_SESSION['login']."' AND
password = '".substr(sha1( $_POST['password']), 0, 10)."'";
$result = mysql_query($sq l);
if (mysql_num_rows ($result) < 1)
{
$msg = "Invalid login and password!";
}
else
{
$row = mysql_fetch_ass oc($result);
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['last_name'] = $row['last_name'];
$_SESSION['security_acces s'] = $row['security_acces s'];
$passwd_date = $row['passwd_date'];
$expire = $row['expire'];
if ($passwd_date + $expire < date('Y-m-j'))
{
header('locatio n: expired.html');
}
else
{
header('locatio n: main.html');
}
}
}
?>
<SCRIPT LANGUAGE="JavaS cript">
function checkrequired(f orm)
{
for(f=0;f<form. length;f++)
{
if(form[f].name.substring (4,length)=="re qd")
{
if(form[f].value){continu e}
else
{
alert("Please fill "+form[f].name.substring (5));
form[f].focus();
return false;
}
}
}
return true;
}
</script>
<form method="post">
Login:<input name="reqd.logi n" type="text"><br >
Password:<input name="reqd.pass word" type="password" ><br>
<input type="submit" name="process" value="Login"
onClick="checkr equired(this)">
</form>
<?php echo($msg); ?>
-------------------------------------------------------
fields with javascript and then run the PHP script. All the scripts
are in one page. I want PHP to control where the next page is. It
works fine without the javascript but when I add the javascript the
page doesn't do anything besides the validation. Thanks for your
help... Chong
----login.html--------------------------------
<?php
ob_start();
session_start() ;
require('dataso urce.html');
switch ($_POST['process'])
{
case 'Login':
$_SESSION['login'] = $_POST['login'];
$sql = "SELECT first_name, last_name, security_access , expire,
passwd_date FROM sy_user WHERE login = '".$_SESSION['login']."' AND
password = '".substr(sha1( $_POST['password']), 0, 10)."'";
$result = mysql_query($sq l);
if (mysql_num_rows ($result) < 1)
{
$msg = "Invalid login and password!";
}
else
{
$row = mysql_fetch_ass oc($result);
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['last_name'] = $row['last_name'];
$_SESSION['security_acces s'] = $row['security_acces s'];
$passwd_date = $row['passwd_date'];
$expire = $row['expire'];
if ($passwd_date + $expire < date('Y-m-j'))
{
header('locatio n: expired.html');
}
else
{
header('locatio n: main.html');
}
}
}
?>
<SCRIPT LANGUAGE="JavaS cript">
function checkrequired(f orm)
{
for(f=0;f<form. length;f++)
{
if(form[f].name.substring (4,length)=="re qd")
{
if(form[f].value){continu e}
else
{
alert("Please fill "+form[f].name.substring (5));
form[f].focus();
return false;
}
}
}
return true;
}
</script>
<form method="post">
Login:<input name="reqd.logi n" type="text"><br >
Password:<input name="reqd.pass word" type="password" ><br>
<input type="submit" name="process" value="Login"
onClick="checkr equired(this)">
</form>
<?php echo($msg); ?>
-------------------------------------------------------
Comment