maron Posted July 16, 2006 Share Posted July 16, 2006 config:IIS server 5PhpMS 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 95Notice: Undefined variable: Lastname in C:\cgi\dataAccess.php on line 95Notice: Undefined variable: PhoneNumber in C:\cgi\dataAccess.php on line 95Warning: 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 81Error in odbc_exec( no cursor returned )================================================== here's my coding1. formInput.php <?phpfunction 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<?phpfunction 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 thepconnect 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 rowswhile( 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 creatinga 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 permissionbased what i saw in my default Webpage & server..thanx in advance.. c",) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.