Anyone have any useful links or code for php script to communicate with an ms access 2003 database.
Had a look on google myself and people are talking about it but i couldn't find any code hints (i've already set up the odbc connection).
Thanks in advance
Scripting PHP
Moderator: Thanas
- Perseid
- Padawan Learner
- Posts: 357
- Joined: 2005-03-10 09:10am
- Location: Somewhere between Here and There
Ok I managed to find a few sites with code that I've modified to work with my db. However I'm getting the following error for the data processing page.
My question is, where am I going wrong.
and my code looks like thisPrevious Entries in database
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4., SQL state 07001 in SQLExecDirect in C:\Program Files\Apache Group\Apache2\htdocs\datasystem.php on line 25
Error in odbc_exec(no cursor returned)
Code: Select all
<?php
function HTML_Head() {
echo
"<html><head>
<title>Process form</title>
</head>";
}
function HTML_Foot() {
echo "</body></html>";
}
function Database_Entries($msg) {
echo $msg;
}
function Output_Entries() {
$cnx=odbc_connect('Taxi','','');
if(!$cnx) {
Error_handler("Error in odbc_connect",$cnx);
}
$cur=odbc_exec($cnx, "select CustNo, Name, Address, Town, PostCode, TelephoneNo, BookingDate from customers");
if (!$cur) {
Error_handler("Error in odbc_exec(no cursor returned)",$cnx);
}
echo "<table border=1><tr><th>Cust No</th><th>Name</th><th>Address</th><th>Town</th>
<th>Post Code</th><th>Telephone No</th><th>Booking Date</th>";
$nbrow=0;
while(odbc_fetch_row($cur)) {
$nbrow++;
$CustNo=odbc_result($rs,"Cust No");
$Name=odbc_result($rs,"Name");
$Address=odbc_result($rs,"Address");
$Town=odbc_result($rs,"Town");
$PostCode=odbc_result($rs, "Post Code");
$PhoneNo=odbc_result($rs,"Telephone No");
$BookingDate=odbc_result($rs,"Booking Date");
echo "<tr><td>$CustNo</td>";
echo "<td>$Name</td>";
echo "<td>$Address</td>";
echo "<td>$Town</td>";
echo "<td>$PostCode</td>";
echo "<td>$PhoneNo</td>";
echo "<td>$BookingDate</td></tr>";
}
echo "<tr><td colspan=2>$nbrow entries</td></tr></table>";
odbc_close($cnx);
}
function Error_Handler($msg,$cnx) {
echo "$msg \n";
odbc_close($cnx);
exit();
}
function Enter_New_Entry($Name,$Address,$Town,$PostCode,$PhoneNo) {
$cnx=odbc_connect('Taxi','','');
if (!$cnx) {
Error_handler("Error in odbc_connect",$cnx);
}
$SQL_Exec_String="Insert into customers (Name, Address, Town, Post Code, Telephone No)
Values('$Name','$Address','$Town','$PostCode','$PhoneNo')";
$cur=odbc_exec($cnx, $SQL_Exec_String);
if(!$cur) {
Error_handler("Error in odbc_exec(no cursor returned)", $cnx);
}
odbc_close($cnx);
}
$strOldEntries="Previous Entries in database";
$strNewEntries="Updated Version of database (after entries)";
HTML_Head();
Database_Entries($strOldEntries);
Output_Entries();
Enter_New_Entry($Name,$Address,$Town,$Postcode,$PhoneNo);
Database_Entries($strNewEntries);
Output_Entries();
HTML_Foot();
?>
My question is, where am I going wrong.