Jump to content

Archived

This topic is now archived and is closed to further replies.

maron

php in ms access... i need help,s0meb0dy give me a hand...??

Recommended Posts

config:
IIS server 5
Php
MS access (mdb)

===========================================================

em newbie using php and ms access can anybody help me?i having problem using  ms access as my database,em gettin errors like this:

Notice: Undefined variable: Firstname in C:\cgi\dataAccess.php on line 95

Notice: Undefined variable: Lastname in C:\cgi\dataAccess.php on line 95

Notice: Undefined variable: PhoneNumber in C:\cgi\dataAccess.php on line 95

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query., SQL state S1000 in SQLExecDirect in C:\cgi\dataAccess.php on line 81
Error in odbc_exec( no cursor returned )

==================================================

here's my coding

1. formInput.php

<?php

function HTML_Head() {
echo "
<HTML><HEAD>
<TITLE>Processing Form</TITLE>
</HEAD>
<BODY BGCOLOR=\"#D5D5AB\">";
}

function HTML_Form() {

echo "
<FORM METHOD=post ACTION=\"dataAccess.php\">
Please enter the details you wish to be inserted into the Access Database.<br>
First Name:<input name=\"Firstname\" type=\"text\" SIZE=\"25\"><br>
Last Name:<input name=\"Lastname\" type=\"text\" SIZE=\"25\"><br>
Phone Number: <input name=\"PhoneNumber\" type=\"text\" SIZE=\"25\"><br>
<p><INPUT type=\"Submit\" name=\"submit\" value=\"Submit\">
</p></form>
";
}

function HTML_Existing() {
echo "Existing database entries";
}

function HTML_Foot() {
echo "</body></html>";
}

HTML_Head();
HTML_Form();
HTML_Existing();
HTML_Foot();

?>

================================================== ==

2. dataAccess.php

<?php

function HTML_Head() {
echo "
<HTML><HEAD>
<TITLE>Processing Form</TITLE>
</HEAD>
<BODY BGCOLOR=\"#D5D5AB\">";
}

function HTML_Foot() {
echo "</body></html>";
}

function Database_Entries($msg) {
echo $msg;
}

function Output_Entries() {
/*
Make the connection to the database. The syntax is
odbc_connect( 'SYSTEM_DSN' , 'USER', 'PASSWORD' );
$cnx will hold the
pconnect is used to establish a persistent database
connection to the Database until the procedure is completed.
*/

$cnx = odbc_connect( 'sample' ,'root', '' );
if (!$cnx) {
Error_handler( "Error in odbc_connect" , $cnx );
}

// send a simple odbc query . returns an odbc cursor
$cur= odbc_exec( $cnx, "select Index,Firstname,Lastname,PhoneNumber from People" );
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}
echo "<table border=1><tr><th>Index</th><th>First Name</th>".
"<th>Last Name</th><th>Phone Number</th></tr>\n";
$nbrow=0; //Local variable to count number of rows

// fetch the succesive result rows
while( odbc_fetch_row( $cur ) ) {
$nbrow++;
$Index= odbc_result( $cur, 1 ); // get the field "Index"
$Firstname= odbc_result( $cur, 2 ); // get the field "FirstName"
$Lastname= odbc_result( $cur, 3 ); // get the field "LastName"
$PhoneNumber= odbc_result( $cur, 4 ); // get the field "PhoneNumber"

echo "<tr><td>$Index</td><td>$Firstname</td>".
"<td>$Lastname</td><td>$PhoneNumber</td></tr>\n";
}

echo "<tr><td colspan=2>$nbrow entries </td></tr></table>";

// close the connection. important if persistent connection are "On"
odbc_close( $cnx);
}

function Error_Handler( $msg, $cnx ) {
echo "$msg \n";
odbc_close( $cnx);
exit();
}

function Enter_New_Entry ($Firstname, $Lastname, $PhoneNumber) {

/*
First, we create a connection to our ODBC source. This is done by creating
a connection. Once this is done, we are returned an ODBC connection number.
We use this number to use the ODBC functions within PHP.
*/

$cnx = odbc_connect( 'sample' , 'root', '' );
if (!$cnx) {
Error_handler( "Error in odbc_connect" , $cnx );
}
$SQL_Exec_String = "Insert Into People (Firstname, Lastname, PhoneNumber)
Values ('$Firstname', '$Lastname', '$PhoneNumber')";

$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 databse (after entries)";

HTML_Head();
Database_Entries($strOldEntries);
Output_Entries();
Enter_New_Entry ($Firstname, $Lastname, $PhoneNumber);
Database_Entries($strNewEntries);
Output_Entries();
HTML_Foot();

?>


can anybody here help me to figure out where i went wrong??
by the way em a little bit sure that em enabled
the write, read, & execute permission
based what i saw in my default Webpage & server..
thanx in advance.. c",)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.