0

I am writing a simple program where i have a HTML page that gets the username and password from the user and sends it to a PHP page. The PHP page connects to an MS access database and retrieves the stored password, compares it with the password given by the user and redirects the user appropriately. The following is the code.

<?php

$username = $_GET["fname"];
$userpass = $_GET["lname"];

$conn = odbc_connect('db1','','');
echo "hello     ";
if (!$conn)
  {exit("Connection Failed: " . $conn);}
 echo "hello2";
$sql="SELECT * FROM login where `username`= $username";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}

odbc_fetch_row($rs);
$dbpass = odbc_result($rs,"password");
if(strcmp($dbpass,$userpass))
    header( 'Location: mainpage.html' );
else
    header( 'Location: index.html' );
odbc_close($conn);

?>

The following is my error.

Warning: odbc_connect() [function.odbc-connect]: SQL error: Failed to fetch error message, SQL state HY000 in SQLConnect in C:\wamp\www\MyFiles\hello.php on line 6

what have I done wrongly??

Please help.

Edited by Dani: Formatting fixed

2
Contributors
10
Replies
18
Views
5 Years
Discussion Span
Last Post by pritaeas
0

the first parameter that I have mentioned is the DSN. I have kept the DSN and the database name the same. Is something else the problem??

I gave 2 echo statements to check where things are going wrong. The first echo statement is getting executed while the second one is not. I dont know why i am not able to establish the connection.

Actually, I know how to get the job done using servlets. But I dont know how to deploy servlets in WAMP. Nor am I able to run tomcat and WAMP through different ports. Also, i dont know anything in PHP. Hence, this confusion.

Please help. I want this code to work :(

0

The second one is only echoed if the connection fails. The same with fetch row. Show your new code without the comments (use code tags). It looks like a logic error.

0
<?php

$username = $_GET["fname"];
$userpass = $_GET["lname"];

$conn = odbc_connect('db1','','');
echo "hello	 	";
if (!$conn)
  {exit("Connection Failed: " . $conn);}
 echo "hello2";
$sql="SELECT * FROM login where username=";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
 
odbc_fetch_row($rs);
$dbpass = odbc_result($rs,"password");
if(strcmp($dbpass,$userpass))
	header( 'Location: mainpage.html' );
else
	header( 'Location: index.html' );
odbc_close($conn);

?>
0

And how does your DSN look ? Because I still see 'db1', and that can't be correct.

Should look like this:

$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

Edited by pritaeas: n/a

0

i changed that. That line is working. But my

$sql="SELECT * FROM login where `username`= $username";

statement is showing error. How should I modify this statement??

0

This is what I want to do.


I want to check if the username and password entered by the user match. My database name is "db1". My table name is "login". It has two fields namely "username" and "password".

Can you please modify the code so that it works properly??

0

I dont know. I started learning PHP yesterday and I really have no clue how to debug the code.

0

Try this:

$sql = "SELECT * FROM login where username = '$username'";

It's not PHP, that's SQL dialect specific, in this case MS Access.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.