How to Use Insert Query In PHP With Access database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hnpatel
    New Member
    • Jan 2008
    • 12

    How to Use Insert Query In PHP With Access database?

    Hi to all,
    How to use insert query in php?
    I m using ODBC connection with access database.I want to save data in table.
    I m using database 'PHPDB1'.
    Table Name 'EDETAIL'.
    There r two fields in table: 'ENO' & 'ENAME'.
    I want to take to text box and one submit button.
    I want to save the value of text box in table when i click on submit button.
    How to do all this process using PHP?
    I had already create connection
    I m using Below code to fetch data from this table.
    It works properly.
    "
    [PHP]$conn=odbc_conn ect('phptest1', '','');
    if (!$conn)
    {exit("Connecti on Failed: " . $conn);}

    //$sql="INSERT INTO edetail(eno)val ues('$_POST[name]')";


    $sql="SELECT * FROM edetail";
    $rs=odbc_exec($ conn,$sql);
    if (!$rs)
    {exit("Error in SQL");}

    echo "<table><tr >";
    echo "<th>ECode</th>";
    echo "<th>EName</th></tr>";
    while (odbc_fetch_row ($rs))
    {
    $eno=odbc_resul t($rs,"eno");
    $ename=odbc_res ult($rs,"ename" );
    echo "<tr><td>$e no</td>";
    echo "<td>$ename </td></tr>";
    }
    odbc_close($con n);
    echo "</table>";

    ?>[/PHP]"

    But i want to save data through form....So plz help me...I Want to learn more about PHP.

    Thanx In Advance.....
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Doesn't line number five work?
    [php]
    $_query = "INSERT INTO `table_name` (`row`) VALUES ('{$_POST['ESCAPED_STRING ']}']";
    ob_exec($_conn, $_query) or die("Error inserting " . odbc_error());
    [/php]
    I can't stress enough that you have to escape user input.

    DONT DOUBLE POST!

    Comment

    Working...