Hello,
I think I’m going to need a little bit of help.
I don’t exactly know where to post this, because it has a little bit of PHP, MySQL and JS.
The PHP script is this:
[code=php]
<?php
mysql_connect(“localhost”, “username”, “password”) or die(mysql_error());
mysql_select_db(“users”) or die(mysql_error());
$result = mysql_query(“SELECT * FROM users”)
or die(mysql_error());
$row = mysql_fetch_array( $result );
$username=$row[‘user’];
$password=$row[‘pass’];
echo “<html>”;
echo “<head>”;
echo “<SCRIPT LANGUAGE=”JavaScript” src=”login.js”>”;
echo “</SCRIPT>”;
echo “</head>”;
echo “<body>”;
echo “<center>”;
echo “<table border=”1″ width=”400″>”;
echo “<tr align=”left”>”;
echo “<td width=”200″>Username:</td>”;
echo “<td width=”200″>”;
echo “<input type=”text” name=”user” size=”35″>”;
echo “</td>”;
echo “</tr>”;
echo “<tr align=”left”>”;
echo “<td width=”200″>Password:</td>”;
echo “<td width=”200″>”;
echo “<input type=”text” name=”passw” size=”35″>”;
echo “</td>”;
echo “</tr>”;
echo “</table>”;
echo “<p />”;
echo “<form name=”login”>”;
echo “<input type=”submit” value=”Login!” onClick=”Login()”>”;
echo “</center>”;
echo “</form>”;
echo “</body>”;
echo “</html>”;
?>
Besides storing the username and password from the database in a variable,
this script echoes the html page which includes a submit bottom
The submit bottom calls a function stores in the “login.js” file.
Here is that JS script:
[CODE]
function Login(){
var done=0;
var user=document.login.user.value;
var passw=document.login.passw.value;
if (user==$username && passw==$password)
{window.open(‘main.html’); done=1;}
if (done==0)
{ alert(“Invalid login!”); }
}
This script compares the username & password typed in the boxes, with the variables from the database (user==$username && passw==$password).
Unfortunately, it just doesn’t seem to work.
When I echo the variables $username and $password I do get the correct info, so that works.
What doesn’t work is compare these with the values from the input fields on the page.
Well, quite a story, and I hope you inderstand what I’m trying to explain.
Any help is very much appreciated ?