1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php can't connecting to access database to be able to insert a new record

Discussion in 'MySQL' started by itsys, Jun 13, 2009.

  1. itsys

    itsys Banned

    Joined:
    May 2, 2009
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    PHP:
    <?php
        $vendorName 
    $_POST["vendorName"];
        
    $address $_POST["address"];
        
    $countryGroup $_POST["countryGroup"];
        
    $city $_POST["city"];
        
    $cost $_POST["cost"];
        
    $provinceList $_POST["provinceList"];
        
    $stateList $_POST["stateList"];
        
    $postalCode $_POST["postalCode"];
        
    $phone $_POST["phone"];
        
    $fax $_POST["fax"];

        print (
    "<br> Vendor Name: $vendorName");
        print (
    "<br> Address: $address");
        print (
    "<br> Country: $countryGroup");
        print (
    "<br> City: $city");
        if (
    $provinceList != "")
        {
            print (
    "<br> Province: $provinceList");
        }
        if (
    $stateList != "")
        {
            print (
    "<br> State: $stateList");
        }
        print (
    "<br> Postal Code: $postalCode");
        print (
    "<br> Phone: $phone");
        print (
    "<br> Fax: $fax");
        
        if (
    $vendorName != "" || $address != "" || $countryGroup != "" || $city != "" || $cost != "" || 
        
    $provinceList != "" || $stateList != "" || $postalCode != "" || $phone != "" || $fax != "")
        {
            
    //$conn=odbc_connect('MyAccess','',''); 
        
            
    $db="D:\Program Files\xampplite\htdocs\As4.mdb";
            
            
    $conn=new COM('ADODB.Connection');
            
            
    $conn->Open("Provider=Microsoft.ACE.OLEDB.12.0;DataSource=$db;");
                
            
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\Program Files\xampplite\htdocs\As4.mdb");
            
            print 
    "<br>TEST TEST TEST 1";
            
            
    $sql="INSERT INTO
            Vendors(VendorName,Address1,Prov,City,Country,PCode,phone,FAX)
            VALUES('
    $vendorName','$address','$provinceList','$city','$countryGroup','$postalCode','$phone','$fax')";
            
            print 
    "<br>TEST TEST TEST 2";
            
            
    $rs=$conn->Execute($sql);
            
            print 
    "<br>TEST TEST TEST 3";
            
            
    $rs->Close();
            
    $conn->Close();
            
    $rs null;
            
    $conn null;
        }
        else
        {
            print(
    "Values not passed correctly please hit back and re-Submit.");
        }
    ?>
     
    Last edited by a moderator: Jun 14, 2009
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    try
    PHP:
    $db="D:\\Program Files\\xampplite\\htdocs\\As4.mdb";
     

Share This Page