Page 1 of 1

How to insert data to Ms access database using php.

Posted: Sun Apr 10, 2005 1:55 am
by anisuzzaman
I already connect to MS access with php. Now please help me....How to insert data to Ms access database using php.

Thanks in advance.
Code below:

Code: Select all

<?php
    if (!$conn = new COM("ADODB.Connection"))
        exit("Unable to create an ADODB connection<br>");
     $strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("SCJPTIS_IDB.mdb");
    $conn->open($strConn);
    $strSQL = "SELECT * FROM PROJECTS ORDER BY [PROJ_ID]";
    $rs = $conn->execute($strSQL);
    $PROJ_ID = $rs->Fields(0);
    $PROJ_NAME = $rs->Fields(1);
   echo "Table: Projects";
      print "<table align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"1\">";
    print "<tr bgcolor=#FFB164><td>ID</td><td>Name</td></tr>";
    while (!$rs->EOF)
    {
        print "<tr bgcolor=\"#1AFFFF\"><td>$PROJ_ID->value</td>";
        print "<td>$PROJ_NAME->value</td></tr>";
        $rs->MoveNext();
    }
    print "</table>";
    $rs->Close();
    $conn->Close();
    $rs = null;
    $conn = null;
?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Apr 10, 2005 7:57 am
by ast3r3x
I don't know because I've never done it before, but maybe this write up from php freaks can help.

Posted: Sun Apr 10, 2005 8:38 am
by Chris Corbyn
Have a read up on the ODBC functions at php.net...

I did this a while ago... it's not "too" dissimilar to MySQL... :wink:

Posted: Sun Apr 10, 2005 11:37 pm
by anisuzzaman
THANKS......

Posted: Mon Apr 11, 2005 3:05 am
by anisuzzaman
Here's the code for insert data..... but not working

Code: Select all

<?php
    if (!$conn = new COM("ADODB.Connection"))
        exit("Unable to create an ADODB connection<br>");
      $strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("SCJPTIS_IDB.mdb");
    $conn->open($strConn);
   $strSQL=odbc_exec($strConn,"insert into PROJECTS(PROJ_ID,PROJ_NAME,PROJ_DESC)VALUES 
('$_POST[PROJ_ID]','$_POST[PROJ_NAME]','$_POST[PROJ_DESC]')");
	       $conn->Close();
 ?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Apr 12, 2005 1:34 am
by anisuzzaman
I have done it..... adding data to access
Now trying for updating and deleting...

I have done it.adding data to access Now trying for update

Posted: Tue Apr 12, 2005 1:39 am
by anisuzzaman
javascript:emoticon(':lol:')