Jump to content

Access Database


Wahoo92583

Recommended Posts

The code below has the basics for inserting into an Access db. You would need to add data validation and data sanitizing.

 

Sample Table customers

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

cust_id    (auto_number)

first_name

last_name

email

 

<?php

/**
* check if data submitted
*/
if (isset($_POST[action])) {
    /**
    * get the form data
    */
    $fn = $_POST['fn'];
    $ln = $_POST['ln'];
    $em = $_POST['em'];
    
    /**
    * connect to database via ODBC DSN
    */
    $cnx = odbc_connect('DSN_NAME','','');    // use your odbc dsn name (must be system dsn)
    
    /**
    * insert data in table 
    */
    $sql = "INSERT INTO customers(first_name, last_name, email)
            VALUES ('$fn', '$ln', '$em')";
    odbc_exec($cnx, $sql);
}  
?>

<form method='post'>
First name   <input type="text" name="fn"><br>
Last name    <input type="text" name="ln"><br>
Email        <input type="text" name="em"><br>
<input type="submit" name="action" value="Add new">
</form>

Link to comment
https://forums.phpfreaks.com/topic/39833-access-database/#findComment-193538
Share on other sites

Archived

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

×
×
  • Create New...

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.