This has got to be a datbase issue because apparently people get this error in nay language they work with. Me? I'm trying to show someone how to connect to an Access database from PHP. I thought this would be relatively easy. Here is the code...
Connection works fine. But I am getting this error:PHP Code:<?php
//Database connection function
function connect_to_access()
{
$access_usr='';
$access_pas='';
$access_dsn = 'DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=c:\user.mdb;';
if(!$cnx = odbc_pconnect($access_dsn,$access_usr,$access_pas))
{
echo 'Could not Connect to Access.';
return false;
}
return $cnx;
}
// Query Function
function query($query,$cnx='')
{
if($cnx == '') #checks to see if database connection
{ #exists and if not creates one
$cnx = connect_to_Access();
}
$sql = odbc_prepare($cnx,$query); #Preps Query for Execution
if (!$result = odbc_exec($cnx,$sql)) #Executes Query and returnd
{ #any errors
echo "Query Failed";
}
return $result;
}
// If Form has not been submitted
if(!isset($_POST['submit']))
{
// Put HTML form in following. Must include a submit button with name="submit"
?>
<form action="auth.php" method="post">
<table>
<tr>
<td>First Name: </td>
<td><input type="text" name="fname" size="20" maxlength="50" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="lname" size="20" maxlength="50" /></td>
</tr>
<tr>
<td colspan=2"><input type="submit" name="submit" value="AUTHENTICATE" /></td>
</tr>
</table>
</form>
<?
exit;
}
else
{
$cnx = connect_to_access();
if(!$sql = query("SELECT *
FROM (Employees)
WHERE FirstName = '".$_POST['fname']."' AND
LastName = '".$_POST['lname']."'"))
{
echo "User is not authenticated";
exit;
}
echo"This one is good";
exit;
}
?>What's going on with the ODBC driver?!Code:Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'., SQL state 37000 in SQLExecDirect in C:\Program Files\Apache Group\Apache2\htdocs\auth.php on line 28 Query FailedUser is not authenticated





Bookmarks